I’m trying to test out a script for a tower defense game we’re working on to create enemy waves, combined a script used to spawn enemies by cloning one on “standby”, but after attaching the Spawner script to the enemy & putting the Waves script in play, Unity just freezes up whenever I try to run things & test it out. Is there something wrong? I knwo things aren’t perfected at the moment, but I just want to see if the initial aspects work.
Here’s the code to spawn enemies:
using UnityEngine;
using System.Collections;
//Attach to one enemy in hierachey, another in assets, summon when needed
public class Spawner : MonoBehaviour {
public GameObject Enemy;
public bool Flood = false;
void Start () {
SpawnIt ();
}
public void Update(){
if(Flood){
SpawnIt();
}
}
public void SpawnIt () {
GameObject[] foundSpawn = GameObject.FindGameObjectsWithTag("SpawnPoint");
GameObject Drone;
Drone = Instantiate(Enemy, foundSpawn[0].transform.position, foundSpawn[0].transform.rotation) as GameObject;
}
}
…And here’s the code to create enemy waves (so far):
using UnityEngine;
using System.Collections;
public class Waves : MonoBehaviour {
int waveCounter = 3;
public void Start () {
while (waveCounter > 0) {
GameObject[] foes = GameObject.FindGameObjectsWithTag("Enemy");
int foesNum = foes.Length;
if (foesNum == 0) {
Spawn ();
waveCounter--;
}
else Debug.Log("You win!");
}
}
public IEnumerator Spawn(){
yield return new WaitForSeconds(5);
GameObject go = GameObject.Find("A*");
for(int x = 0; x < 3; x++) {
go.GetComponent<Spawner>().SpawnIt();
}
}
}
…Any ideas as to what’s causing things to freeze?