How to Spawn a Gameobject According to a Timer?

Hi, Im making a game where I want, in the first wave for 10 enemies to spawn (Get activated) as the game starts, and then 20 more after 5 minutes has gone by. I’ve tried to figure it out, and was unsuccessful. Any help would be awesome! :slight_smile:

function Start()
{
    gameObject.SetActive(false);
}
 
function Update () {
 
    if (Time.time > 300)
    {
       gameObject.SetActive(true);
    }
}

When you disable a game object, you no longer receive Update() calls. So any solution that uses Update() will fail. One solution is to use a boolean flag rather than disabling the game object. But if you must disable the game object, Invoke() still works with disabled game objects. You can do:

function Start() {
	Invoke("Reenable", 300);
	gameObject.SetActive(false);
}
  
function Reenable() {
	gameObject.SetActive(true);
}

This should get the effect you want

public GameObject spawner
float timer = 300;
float time = 0;

function Start()
{
 spawner.SetActive(false);
}

function Update()
{
 if(time >= timer)
 {
  spawner.SetActive(true);
 }
 time += Time.deltaTime;
}

I hope this helps, let me know how you get on