Hi everyone I have this script where as to when i hit a trigger my enemy spawns at a random time then the enemy destroy itself at a random time. I want to respawn the enemy again so it can do this over and over again. Any Suggestions:
public class SpawnManager : MonoBehaviour {
public GameObject Enemy; // the enemy prefab
public float mytimer; // the time to wait before spawn
public float transport;// the time it has to destroy itself
private GameObject _spawndEnemy; // the enemy that was spawnd
void SpawnEnemy()
{
var enemySpawnPoint = GameObject.Find("FFEnemySpawn1").transform;
_spawndEnemy = Instantiate(Enemy, enemySpawnPoint.position, enemySpawnPoint.rotation) as GameObject;
transport = Random.Range (2,15);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "FFTrigger") {
mytimer = Random.Range(0,15);
Invoke("SpawnEnemy", mytimer);
Debug.Log("Spawn Normal");
}
}
void Update()
{
Destroy (_spawndEnemy, transport);
}
}