33 lines
940 B
C#

using System.Collections;
using UnityEngine;
public class AntsNest : Odorant {
public Ant antPrefab;
public uint numberOfAnts = 1;
public bool spawnAnt = false;
private uint antCount = 0;
protected virtual void Start() {
StartCoroutine(SpawnAnts());
}
IEnumerator SpawnAnts() {
while (numberOfAnts > 0) {
Ant ant = Instantiate(antPrefab);
ant.transform.eulerAngles = 360 * Random.value * Vector3.up;
ant.transform.position = this.transform.position + ant.transform.forward * 0.1F;
ant.name = "Ant " + (++antCount);
numberOfAnts--;
yield return new WaitForSeconds(0.2f);
}
}
protected virtual void Update() {
if (spawnAnt) {
Ant ant = Instantiate(antPrefab);
ant.name = "Ant " + (++antCount);
spawnAnt = false;
}
}
}