VIDEDemoPlayer.cs
2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using VIDE_Data;
public class VIDEDemoPlayer : MonoBehaviour
{
//This script handles player movement and interaction with other NPC game objects
public string playerName = "VIDE User";
//Reference to our diagUI script for quick access
public VIDEUIManager1 diagUI;
public QuestChartDemo questUI;
public Animator blue;
//Stored current VA when inside a trigger
public VIDE_Assign inTrigger;
//DEMO variables for item inventory
//Crazy cap NPC in the demo has items you can collect
public List<string> demo_Items = new List<string>();
public List<string> demo_ItemInventory = new List<string>();
void OnTriggerEnter(Collider other)
{
if (other.GetComponent<VIDE_Assign>() != null)
inTrigger = other.GetComponent<VIDE_Assign>();
}
void OnTriggerExit()
{
inTrigger = null;
}
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
//Only allow player to move and turn if there are no dialogs loaded
if (!VD.isActive)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * 5, 0);
float move = Input.GetAxisRaw("Vertical");
transform.position += transform.forward * 7 * move * Time.deltaTime;
blue.SetFloat("speed", move);
}
//Interact with NPCs when pressing E
if (Input.GetKeyDown(KeyCode.E))
{
TryInteract();
}
//Hide/Show cursor
if (Input.GetMouseButtonDown(0))
{
Cursor.visible = !Cursor.visible;
if (Cursor.visible)
Cursor.lockState = CursorLockMode.None;
else
Cursor.lockState = CursorLockMode.Locked;
}
}
//Casts a ray to see if we hit an NPC and, if so, we interact
void TryInteract()
{
/* Prioritize triggers */
if (inTrigger)
{
diagUI.Interact(inTrigger);
return;
}
/* If we are not in a trigger, try with raycasts */
RaycastHit rHit;
if (Physics.Raycast(transform.position, transform.forward, out rHit, 2))
{
//Lets grab the NPC's VIDE_Assign script, if there's any
VIDE_Assign assigned;
if (rHit.collider.GetComponent<VIDE_Assign>() != null)
assigned = rHit.collider.GetComponent<VIDE_Assign>();
else return;
if (assigned.alias == "QuestUI")
{
questUI.Interact(); //Begins interaction with Quest Chart
} else
{
diagUI.Interact(assigned); //Begins interaction
}
}
}
}