What's the most efficient way to time events?

Up until now, whenever I needed to time something like an animation or the rate at which enemies spawn in a game I would use an integer variable to which I would add 1 on the update function. When that number reached a certain amount (say 120 if I wanted a 2 seconds delay), It would activate whatever needed to be activated.

It does, however, feel like a really primitive method, and I’m wondering what is usually used for timing events. Also, would changing the method affect performance?

Yes, it’s usually a good idea to do as little as possible in Update, usually only checking for user input. There are generally two ways to time code: Coroutines and using Invoke. Especially if you’re new, coroutines can take some effort to get into, Invoke is usually the easier method. Of course both of those are much more performance-friendly than changing a value in Update, even though if it’s not thousands of scripts doing that, it shouldn’t be a big issue either. What can be an issue, though, is that not all frames last the same amount of time, so if you ever need to use that method again, make sure to use FixedUpdate. Again, though, coroutines and Invoke are far superior.

essentially the opposite of your current way to be honest. Typically my countdown timers tend to look like this.

var timer : float = 20;

function Update()
{
timer -= Time.deltaTime;
if(timer < 0)
{
doSomeCoolStuff();
timer = 20;
}
}

function doSomeCoolStuff()
{
print("Hello World");
}

and then I would evolve from there.

Hope this helps!