-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathTimedSpawn.ts
33 lines (28 loc) · 988 Bytes
/
TimedSpawn.ts
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
// START MARKER Timed Spawn
import { Behaviour, GameObject, LogType, serializeable, showBalloonMessage, WaitForSeconds } from "@needle-tools/engine";
export class TimedSpawn extends Behaviour {
@serializeable(GameObject)
object?: GameObject;
interval: number = 1000;
max: number = 100;
private spawned: number = 0;
awake() {
if (!this.object) {
console.warn("TimedSpawn: no object to spawn");
showBalloonMessage("TimedSpawn: no object to spawn", LogType.Warn);
return;
}
GameObject.setActive(this.object, false);
this.startCoroutine(this.spawn())
}
*spawn() {
if (!this.object) return;
while (this.spawned < this.max) {
const instance = GameObject.instantiate(this.object);
GameObject.setActive(instance!, true);
this.spawned += 1;
yield WaitForSeconds(this.interval / 1000);
}
}
}
// END MARKER Timed Spawn