-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenemyLauncher.cs
37 lines (33 loc) · 970 Bytes
/
enemyLauncher.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
using UnityEngine;
using System.Collections;
public class enemyLauncher : MonoBehaviour {
public GameObject[] enemyTypes;
private GameObject enemy;
private bool emitting = false;
private IEnumerator coroutine;
// Use this for initialization
void Start () {
coroutine = Emit(6.0f);
}
// Update is called once per frame
void Update ()
{
if (GameController.gameOn && !emitting) {
StartCoroutine(coroutine);
emitting = true;
}else if (!GameController.gameOn) {
StopCoroutine(coroutine);
emitting = false;
}
}
private IEnumerator Emit (float waitTime)
{
while (true) {
int choice = Mathf.CeilToInt(enemyTypes.Length * Random.Range(0.0f, 1.0f)) - 1;
enemy = enemyTypes[choice];
GameObject thisproj = Instantiate (enemy, this.transform.position, this.transform.rotation) as GameObject;
Object.Destroy(thisproj, 10.0f);
yield return new WaitForSeconds(waitTime * Random.Range(1.0f, 2.0f));
}
}
}