Function Update + Yield WaitForSeconds = :( ?

PLEASE HELP MEEEEEE!!!

Hi everyone - I am a noob. Just thought I’d get that out of the way. Ok, I am making a game and I am trying to make a day/night cycle thing. To do that, I’m going to need like a time variable, which starts off at 1, and gets bigger by 1 every second. Like I kind of counter thing. So, to make that, I first tried this:

var time : int = 0;

function Update() {
time = (time + 1);
}

But of course, this just went up by 1 every frame. So, I though if I put in a WaitForSeconds command, it would work fine, like this:

var time : int = 0;

function Update() {
time = (time + 1);
yield WaitForSeconds (1);
}

But it didn’t work, and I have no idea why. Does anyone know why this isn’t working?
Thank you, and may the almighty Lord Notch bless you. :smile:

Update cannot be a coroutine. It runs once every frame, always, with no exceptions; it can never be delayed. Look up InvokeRepeating instead.

–Eric

Thanks man, it worked!
:smile:

You might already be aware of this, but Time.timeSinceLevelLoad does exactly the same thing (it will feed you a float which increases by 1 per second); no repeating function necessary.