-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spawner.cs
72 lines (61 loc) · 1.57 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawner : MonoBehaviour
{
[SerializeField]
public float begin_cooldown = 2;
[SerializeField]
public float begin_velocity = 10;
[SerializeField]
private GameObject spawn_object;
[SerializeField]
[InspectorName("Count controller")]
private CountObjController coco;
private float time;
private float cooldown;
private float velocity;
SpawnerBody[] spawners;
void Start()
{
spawners = getSpawnerBodies();
time = 0;
cooldown = begin_cooldown;
velocity = begin_velocity;
}
void Update()
{
time += Time.deltaTime;
if (time > cooldown)
{
time -= cooldown;
if (coco.can_add())
{
SpawnerBody sb = spawners[Random.Range(0, spawners.Length)];
sb.spawn(spawn_object, velocity);
coco.add();
}
}
}
private SpawnerBody[] getSpawnerBodies()
{
List<SpawnerBody> spawners = new List<SpawnerBody>();
foreach (var item in gameObject.GetComponentsInChildren<SpawnerBody>())
{
if (item.CompareTag("SpawnerBody"))
{
spawners.Add(item);
}
}
return spawners.ToArray();
}
public void updateCooldown(float cooldown)
{
this.cooldown = cooldown;
}
public void updateVelocity(float velocity)
{
Debug.Log(velocity);
this.velocity = velocity;
}
}