Hi I am quite new to this so I need a bit of help I want spawner that delay's the spawn for a set amout of time. So I decided to use a coroutine to delay the spawn. but for some reason that i can figure out its not executing. here is the code for my zombie spawner script.
using UnityEngine;
using System.Collections;
public class ZombieSpawner : MonoBehaviour {
public int EnemysPerMinute;
private float TimeBetweenSpawn;
public GameObject Zombie;
// Use this for initialization
void Start ()
{
TimeBetweenSpawn = 60 / EnemysPerMinute;
StartCoroutine(Spawn_Zombie());
}
IEnumerator Spawn_Zombie()
{
yield return new WaitForSeconds(TimeBetweenSpawn);
Instantiate(Zombie, transform.position, Quaternion.identity);
}
hey I managed to get it to work, I dont really know how it just sort of started working. Anyways can I ask how can I get it to repeat itself again and again?
thanks all
Yes Sorry i Should post the new code, i couldnt get invoke repeating to work so i went for a different approach
in "void start()"
i have StartCoroutine(Spawn_Zombie());
and then i have the actual coroutine
// spawns the zombie after certain time an then repeats
IEnumerator Spawn_Zombie()
{
yield return new WaitForSeconds(TimeBetweenSpawn);
Instantiate(Zombie_Left, transform.position, Quaternion.identity);
StartCoroutine(Spawn_Zombie());
}
//terminates the zombie spawner after certain time
IEnumerator Stop_Spawning()
{
yield return new WaitForSeconds(TimeToSpawnEnemys);
Destroy(this.gameObject);
}