-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointNClick.cs
More file actions
294 lines (259 loc) · 11.2 KB
/
PointNClick.cs
File metadata and controls
294 lines (259 loc) · 11.2 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
using UnityEngine;
using System.Collections;
public class PointNClick : MonoBehaviour {
Vector3 touchPos;
Vector3 target;
public GameObject player;
public GameObject targetSelected;
public GameObject persistentObject;
public GUISkin customGUISkin;
public AudioClip audioDepressed;
public AudioClip audioDefault;
float speed = 1f;
float startSpotAngle;
public bool move = false;
public string movingTo = "point";
public float targetColliding;
public float stateOfDepression = 0; //the higher, the more depressed;
public int currentDay = 0; //monday through sunday, 0-3
public int currentAction = 0; // What should you do now? Talk to the main patient, a patient in general or just go home? Actions are define in numbers
public bool showMessage = false;
public bool playerWillCollide = false; // If true when the player collides with wall, she will stop.
//Message box attributes
int msgBoxLeft = 10;
int msgBoxTop = 10;
int msgBoxWidth = 128;
int msgBoxHeight = 64;
Rect rectMsgBox;
//message box's button attributes
//many of the attributes are dependant on the message box's attributes. I will thus not write them.
int msgButtonHeight = 32;
Rect rectMsgButton;
//Message
public string msgText = "text";
void Awake()
{
if (stateOfDepression <= -20)
{
GetComponent<AudioSource>().clip = audioDepressed;
GetComponent<AudioSource>().Play();
}
if (stateOfDepression >= 0)
{
GetComponent<AudioSource>().clip = audioDefault;
GetComponent<AudioSource>().Play();
}
startSpotAngle = player.transform.FindChild("Spotlight").GetComponent<Light>().spotAngle;
player.GetComponent<Animation>().wrapMode = WrapMode.Loop;
player.GetComponent<Animation>()["Take 001"].speed = 0;
rectMsgBox = new Rect(msgBoxLeft, msgBoxTop, msgBoxWidth, msgBoxHeight);
rectMsgButton = new Rect(msgBoxLeft, msgBoxHeight, msgBoxWidth, msgButtonHeight);
}
void Update () {
// Moves the character if allowed
if (move == true) {
player.transform.Translate(new Vector3(0, 0, speed * Time.deltaTime));
}
else {
player.transform.Translate(Vector3.zero);
}
// detects whether you're close to the target or not. If you are, then you stop and perform the actions
// based on what target you're moving to.
if (Vector3.Distance(player.transform.position, target) < targetColliding )
{
player.GetComponent<Animation>()["Take 001"].speed = 0;
switch (movingTo)
{
case "Colleague":
targetSelected = GameObject.Find("Colleague");
move = false;
if (targetSelected.GetComponent<Interaction>().beginDialogue != true)
{
movingTo = "Colleague";
targetSelected.GetComponent<Interaction>().TalkingTo = 1;
targetSelected.GetComponent<Interaction>().ChangeCase();
targetSelected.GetComponent<Interaction>().beginDialogue = true;
showMessage = false;
}
movingTo = "point";
break;
case "Patient":
targetSelected = GameObject.Find("Patient");
move = false;
if (currentAction == 0)
{
if (targetSelected.GetComponent<Interaction>().beginDialogue != true)
{
targetSelected.GetComponent<Interaction>().TalkingTo = 0;
targetSelected.GetComponent<Interaction>().beginDialogue = true;
showMessage = false;
movingTo = "point";
}
}
else
{
ShowMessage("Patienten er ikke snaksaglig lige nu.");
}
break;
case "MainPatient":
targetSelected = GameObject.Find("MainPatient");
move = false;
if (currentAction == 1)
{
if (targetSelected.GetComponent<MainStory>().beginDialogue != true)
{
targetSelected.GetComponent<MainStory>().ChangeCase();
targetSelected.GetComponent<MainStory>().beginDialogue = true;
showMessage = false;
}
movingTo = "point";
}
else
{
if (currentAction == 0)
{
ShowMessage("Der er andre patienter, som du lige skal se til.");
}
else { ShowMessage("Dagen er snart ovre. Du må hellere gå hjem."); }
}
break;
case "ExitDoor":
targetSelected = GameObject.Find("ExitDoor");
if (currentDay < 2)
{
if (currentAction == 2)
{
ShowMessage("En ny dag begynder.");
GameObject patient = GameObject.Find("Patient");
GameObject colleague = GameObject.Find("Colleague");
movingTo = "point";
currentDay++;
patient.GetComponent<Interaction>().currentCase++;
colleague.GetComponent<Interaction>().currentCase++;
NewDay();
}
else
{
ShowMessage("Du kan ikke gå hjem nu.");
}
}
else if (currentDay == 2)
{
if (currentAction == 2)
{
Application.LoadLevel(2);
}
}
move = false;
break;
default:
move = false;
break;
}
}
// when clicking on the screen with the cursor
if (Input.GetMouseButtonDown(0))
{
// init. these variables to get where you click and to setup for a raycast
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
// raycast is used to check if the clicked area is walkable (ie. the ground)
if (Physics.Raycast(ray.origin, ray.direction, out hit))
{
switch (hit.collider.name)
{
case "Ground":
movingTo = "Ground";
move = true;
target = new Vector3(hit.point.x, player.transform.position.y, hit.point.z);
targetColliding = 0.2f;
player.transform.LookAt(target);
player.GetComponent<Animation>()["Take 001"].speed = 5;
break;
case "Colleague":
movingTo = "Colleague";
move = true;
target = new Vector3(hit.point.x, player.transform.position.y, hit.point.z);
player.transform.LookAt(target);
targetColliding = hit.collider.bounds.size.x / 2 + player.collider.bounds.size.x / 2;
player.GetComponent<Animation>()["Take 001"].speed = 5;
break;
case "Patient":
movingTo = "Patient";
move = true;
target = new Vector3(hit.point.x, player.transform.position.y, hit.point.z);
player.transform.LookAt(target);
targetColliding = hit.collider.bounds.size.x/2 + player.collider.bounds.size.x/2;
player.GetComponent<Animation>()["Take 001"].speed = 5;
break;
case "MainPatient":
movingTo = "MainPatient";
move = true;
target = new Vector3(hit.point.x, player.transform.position.y, hit.point.z);
player.transform.LookAt(target);
targetColliding = hit.collider.bounds.size.x / 2 + player.collider.bounds.size.x / 2;
player.GetComponent<Animation>()["Take 001"].speed = 5;
break;
case "ExitDoor":
movingTo = "ExitDoor";
move = true;
target = new Vector3(hit.point.x, player.transform.position.y, hit.point.z);
player.transform.LookAt(target);
targetColliding = hit.collider.bounds.size.x / 2 + player.collider.bounds.size.x / 2;
player.GetComponent<Animation>()["Take 001"].speed = 5;
break;
}
}
}
}
void OnGUI()
{
if (showMessage)
{
GUI.Box(rectMsgBox,msgText,customGUISkin.box);
if (GUI.Button(rectMsgButton, "Okay.",customGUISkin.button))
{
showMessage = false;
movingTo = "point";
}
}
}
public void refreshDepression()
{
player.transform.FindChild("Spotlight").GetComponent<Light>().spotAngle = startSpotAngle + stateOfDepression;
if (stateOfDepression <= -20)
{
persistentObject.GetComponent<PersistentObject>().depressed = 0;
if (GetComponent<AudioSource>().clip != audioDepressed)
{
GetComponent<AudioSource>().clip = audioDepressed;
GetComponent<AudioSource>().Play();
}
}
if (stateOfDepression >= 0)
{
persistentObject.GetComponent<PersistentObject>().depressed = 1;
if (GetComponent<AudioSource>().clip != audioDefault)
{
GetComponent<AudioSource>().clip = audioDefault;
GetComponent<AudioSource>().Play();
}
}
}
void ShowMessage(string newText)
{
msgText = newText;
showMessage = true;
}
void NewDay()
{
currentAction = 0;
// Starts a new day. Inits Interactions NewDay Method which resets it's cases. Also places doctor's position.
GameObject.Find("Patient").GetComponent<Interaction>().NewDay();
GameObject.Find("Colleague").GetComponent<Interaction>().NewDay();
player.transform.position = new Vector3(
GameObject.Find("StartPos").transform.position.x,
0,
GameObject.Find("StartPos").transform.position.z);
}
}