-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTaskControl.cs
More file actions
92 lines (84 loc) · 2.72 KB
/
TaskControl.cs
File metadata and controls
92 lines (84 loc) · 2.72 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
using System;
using UnityEngine;
using Valve.VR.InteractionSystem;
public class TaskControl : MonoBehaviour
{
BoardUIManager UIManager;
/* Task state is one of
* Idle | InTrial
*/
string TaskState;
int toggleUI = 1;
float trialStartTime;
void Start()
{
UIManager = GameObject.Find("Board").GetComponent<BoardUIManager>();
//UIManager.SetBoardDisplay(true);
UIManager.ActivateConfirmButton(true);
TaskState = "Idle";
}
void GenerateItems()
{
GameObject goldBar = Resources.Load<GameObject>("Prefabs/i_gnot");
var rnd = new System.Random(DateTime.Now.Millisecond);
double tick_1 = rnd.NextDouble();
double tick_2 = rnd.NextDouble();
GameObject initGoldBar = Instantiate(goldBar, new Vector3((float)(5 * tick_1 - 4.0), 0.5f, (float)(5 * tick_2 - 0.5)), Quaternion.identity);
initGoldBar.name = "goldbar";
}
// Update is called once per frame
void Update()
{
// Universal action
if (UIManager.userAction == "MenuButtonPressed")
{
toggleUI ^= 1;
UIManager.SetBoardDisplay(Convert.ToBoolean(toggleUI));
UIManager.userAction = "";
}
if (TaskState == "Idle")
{
if (UIManager.boardCommand == "ConfirmButtonPressed")
{
GenerateItems();
UIManager.SetBoardDisplay(false);
toggleUI = 0;
trialStartTime = Time.time;
UIManager.boardCommand = "";
TaskState = "InTrial";
}
}
else if (TaskState == "InTrial")
{
bool foundObject = false;
Player player = Player.instance;
if (player)
{
foreach (Hand hand in player.hands)
{
GameObject attachedObject = hand.currentAttachedObject;
if (attachedObject != null)
{
foundObject = true;
}
}
}
if (foundObject)
{
UIManager.SetBoardDisplay(true);
UIManager.SetMainText("You found the object! Click to continue");
toggleUI = 1;
TaskState = "Idle";
Destroy(GameObject.Find("goldbar"));
}
if ((Time.time - trialStartTime > 60) && !foundObject)
{
UIManager.SetBoardDisplay(true);
UIManager.SetMainText("Time is up! Click to to try again");
toggleUI = 1;
TaskState = "Idle";
Destroy(GameObject.Find("goldbar"));
}
}
}
}