Repository navigation
Expand file tree
/
Copy pathSpawnWave.cs
More file actions
49 lines (44 loc) · 1.71 KB
/
Copy pathSpawnWave.cs
File metadata and controls
49 lines (44 loc) · 1.71 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
using UnityEngine;
using System.Collections;
public class SpawnWave : MonoBehaviour
{
public GameObject enemy;
public float spawnnerSize;
public int hazardCount;
public float spawnWait;
public float startWait;
public float waveWait;
public float speed;
public Vector2 targetPosition;
public bool horizontal;
void Start ()
{
StartCoroutine (SpawnWaves ());
}
IEnumerator SpawnWaves ()
{
yield return new WaitForSeconds (startWait);
while (true)
{
for (int i = 0; i < hazardCount; i++)
{
if (horizontal) {
Vector3 spawnPosition = new Vector3(transform.position.x, Random.Range(transform.position.y - spawnnerSize, transform.position.y + spawnnerSize), transform.position.z);
Quaternion spawnRotation = Quaternion.identity;
GameObject enemyInstance;
enemyInstance = Instantiate(enemy, spawnPosition, spawnRotation) as GameObject;
enemyInstance.GetComponent<Rigidbody2D>().AddForce(targetPosition * speed * 5000);
}
else {
Vector3 spawnPosition = new Vector3(Random.Range(transform.position.x - spawnnerSize, transform.position.x + spawnnerSize), transform.position.y, transform.position.z);
Quaternion spawnRotation = Quaternion.identity;
GameObject enemyInstance;
enemyInstance = Instantiate(enemy, spawnPosition, spawnRotation) as GameObject;
enemyInstance.GetComponent<Rigidbody2D>().AddForce(targetPosition * speed * 5000);
}
yield return new WaitForSeconds (spawnWait);
}
yield return new WaitForSeconds (waveWait);
}
}
}