-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpawnManagerScript.cs
More file actions
63 lines (51 loc) · 1.79 KB
/
SpawnManagerScript.cs
File metadata and controls
63 lines (51 loc) · 1.79 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManagerScript : MonoBehaviour
{
[SerializeField] private GameObject[] enemyPrefabs;
[SerializeField] private GameObject[] powerUps;
private GameManagerScript GM = null;
private PlayerScript player = null;
bool gameOver = false;
Vector3[] spawnSide = { new Vector3(-6.5f, -2.97f, 0), new Vector3(6.5f, -2.97f, 0) };
// Start is called before the first frame update
void Start()
{
GM = GameObject.Find("GameManager").GetComponent<GameManagerScript>();
}
// Update is called once per frame
void Update()
{
}
public void StartSpawn()
{
StartCoroutine(EnemySpawnRoutine());
StartCoroutine(PowerUpSpawnRoutine());
}
IEnumerator EnemySpawnRoutine()
{
while (!GM.gameOver)
{
int randomPowerUp = Random.Range(0, 2);
Instantiate(enemyPrefabs[randomPowerUp], spawnSide[randomPowerUp], Quaternion.identity);
yield return new WaitForSeconds(5.0f);
}
}
IEnumerator PowerUpSpawnRoutine()
{
while (!GM.gameOver)
{
player = GameObject.Find("Player").GetComponent<PlayerScript>();
float xPos = Random.Range(-6.5f, 6.5f);
if (xPos < player.transform.position.x + 1f && xPos > player.transform.position.x - 1f && player != null)
{
xPos += 1f;
}
int randomPowerUp = Random.Range(0, 5); // inclusive, exclusive
Instantiate(powerUps[randomPowerUp], new Vector3(xPos, 6.5f, 0),
Quaternion.identity);
yield return new WaitForSeconds(5.0f);
}
}
}