-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpawner.cs
49 lines (38 loc) · 1.33 KB
/
Spawner.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
using System.Collections;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Spawner : MonoBehaviour {
public GameObject[] enemies;
public Vector3 spawnValues;
public float spawnWait;
public float spawnMostWait;
public float spawnLeastWait;
public int startWait;
public bool stop;
public GameObject ScoreText;
public static double theScore = 1;
//Use this for initialization
int randEnemy;
void Start () {
StartCoroutine(waitSpawner());
theScore = 1;
}
// Update is called once per frame
void Update () {
spawnWait = Random.Range(spawnLeastWait, spawnMostWait);
ScoreText.GetComponent<Text>().text = "SCORE: " + theScore;
theScore = theScore + 1;
}
IEnumerator waitSpawner()
{
yield return new WaitForSeconds (startWait) ;
while (!stop)
{
randEnemy = Random.Range (0, 2);
Vector3 spawnPosition = new Vector3(Random.Range(-spawnValues.x, spawnValues.x), 1, Random.Range(-spawnValues.z, spawnValues.z));
Instantiate(enemies[randEnemy], spawnPosition + transform.TransformPoint(0, 0, 0), gameObject.transform.rotation);
yield return new WaitForSeconds(spawnWait);
}
}
}