-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpawningScript.cs
98 lines (88 loc) · 3.19 KB
/
SpawningScript.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawningScript : MonoBehaviour {
//public GameObject prefab;
//GameObject clone;
public GameObject enemies;
public float spawnWait;
public float spawnMostWait;
public float spawnLeastWait;
public int startWait;
bool dumpVar;
public static int parasOnLeft;
public static int parasOnRight;
public static bool reachedTurret;
public static bool stopGame;
public static bool destroyedTurret;
public static bool reinitialised;
public GameObject explosion;
public GameObject temp_exp; // Temporary object for instantiating explosion
public GameObject helicopter; // Temporary object for instantiating helicopter
int spawnColumn;
float columny;
float helicopterRandomVar;
void Start () {
Debug.Log ("Initialising Spawning Script");
startWait = 2;
spawnLeastWait = 0.8f;
spawnMostWait = 2f;
parasOnLeft = 0;
parasOnRight = 0;
reachedTurret = false;
dumpVar = false;
destroyedTurret = false;
stopGame = false;
reinitialised = false;
Debug.Log ("Right before Start Coroutine");
StartCoroutine (Spawn ());
Debug.Log ("Right after Start Coroutine");
}
void Update () {
if (reinitialised) {
StartCoroutine (Spawn ());
reinitialised = false;
}
spawnWait = Random.Range (spawnLeastWait, spawnMostWait);
if (reachedTurret & !dumpVar) {
dumpVar = true;
Invoke ("destroyTurret", 5f);
}
}
IEnumerator Spawn () {
yield return new WaitForSeconds (startWait);
while ((parasOnLeft < 4) & (parasOnRight < 4)) {
Debug.Log ("Inside recursively called Spawn function");
spawnColumn = Random.Range (0, 3);
if (spawnColumn == 0)
columny = 4.45f;
else if (spawnColumn == 1)
columny = 3.45f;
else
columny = 2.45f;
helicopter = (GameObject) Instantiate (enemies);
helicopter.transform.rotation = Quaternion.identity;
if (spawnColumn == 1) {
helicopter.transform.position = new Vector3 (9.6f - 0.5f, columny, 0);
helicopter.SendMessage ("assignDirection", false);
} else {
helicopter.transform.position = new Vector3 (-9.6f - 0.5f, columny, 0);
helicopter.SendMessage ("assignDirection", true);
}
yield return new WaitForSeconds (spawnWait);
}
}
public void destroyTurret () {
StartCoroutine (DestroyTurretFunction ());
}
IEnumerator DestroyTurretFunction () {
temp_exp = (GameObject) Instantiate (explosion, new Vector3 (0f, -3.93f, 0), Quaternion.identity);
yield return new WaitForSeconds (1.5f);
destroyedTurret = true;
GameObject turret = GameObject.FindGameObjectWithTag ("playerWeapon");
Destroy (turret);
GameObject theend = GameObject.FindGameObjectWithTag ("Finish");
yield return new WaitForSeconds (3.17f);
Destroy (theend);
}
}