-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHadesSpawnObjects.cs
47 lines (32 loc) · 1.47 KB
/
HadesSpawnObjects.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HiddenUnits {
public class HadesSpawnObjects : MonoBehaviour {
public void Start()
{
TeamHolder = GetComponentInParent<TeamHolder>() ?? gameObject.AddComponent<TeamHolder>();
if (spawnOnStart)
{
SpawnObjects();
}
}
public void SpawnObjects() { StartCoroutine(DoSpawning()); }
public IEnumerator DoSpawning() {
for (var i = 0; i < amountToSpawn; i++) {
var point = new Vector3(transform.position.x + Random.Range(-radius, radius), transform.position.y + 2f, transform.position.z + Random.Range(-radius, radius));
var spawnedObject = Instantiate(objectsToSpawn[Random.Range(0, objectsToSpawn.Count)], point, Quaternion.LookRotation(Vector3.up));
var team = spawnedObject.AddComponent<TeamHolder>();
team.team = TeamHolder.team;
team.spawner = TeamHolder.spawner;
yield return new WaitForSeconds(delayPerSpawn);
}
}
private TeamHolder TeamHolder;
public List<GameObject> objectsToSpawn = new List<GameObject>();
public int amountToSpawn = 10;
public float radius = 8f;
public float delayPerSpawn = 0.08f;
public bool spawnOnStart = true;
}
}