Skip to main content
8 of 16
added 509 characters in body
ShoulO
  • 509
  • 2
  • 6

First: are you sure that you set different value of variable delay for each object/ minion?? Because problem is here: Time.time is a number of seconds that has passed from starting the game. So it will be the same for all objects! So if all minions has variable delay set to 3, and Time.time is equal thought the game - means after 3 seconds Time.time+3 will be exactly equal to each object/minion!

In short, your problem is that you are counting time from begging of the game, which is equal to all objects.

Second: When I want to delay something I almost always use Coroutines. You can specify the time for delay, and since they are asynchronous, so each object can have its own timer running - independent of each other. Also you can start Coroutines and stop them.

Over the time I found that often even more convenient (less code) is InvokeReapeating or just Invoke - you specify time when to fire a function, and that's it. And again each object can have its own timer.

Update() timers gets messy, especially if a lot is happening inside Update() function.

P.S. I do not normally use Update(). In most cases of delays, waypoints, cooldowns, respawns, etc.- Coroutines or InvokeRepeating or Invoke do the job brilliantly, without affecting the rest of the code.

Here would be example of code sending different minion every three seconds: In your main or manager script you write:

public List<GameObject> minions = new List<GameObject>(); void Start() { InvokeRepeating("SendOneMinion", 3, 3); } int count=0; public void SendOneMinion() { if (count >= minions.Count) minions[count].GetComponent<Waypoints>().GoRightNow(); else CancelInvoke(); count++; } 
ShoulO
  • 509
  • 2
  • 6