The equivalent of “async” in Unity 5.3.4?

Hey, I’m working on a new game which uses the 5.3.4 unity engine and can’t upgrade it.
I have to build an radio, which need to wait untill the last song is ending and destroy it, I did made sure that in the “Destroy” function I gave it the exact time but that’s not the problem, after the first song the radio stops playing becasue the function isn’t being called anymore, so I have to put everything on a “while” loop, but for it to work – I have to use “async await” or some sort of timer so the while function won’t spam it and make the game crash, so, what I need to solve that bug is some sort of timer or some sort of code that will hold and won’t do anything untill the time pass. (I can’t use “async await” because the unity is 5.3.4, so the c# is version 4# and for that I need 5#.

Unity provides a bunch of different ways to do timed events.

The main game loop calls Update every frame, and you can store a “wait until X” time value in a variable, and check Time.time against that variable in later Update’s.

If you need “some code - wait - some more code” type code, you can use Coroutines.

1 Like

Tried to use Coroutines, not working.
I even tried to create a new function of IEnumerator and the unity crashs for the same reason - infinite while that needs to be stopped by an “await-asynic” alike functon.
And I’ve already tried using the threat, what it does is just make everythiing go slower and it dosen’t works anyway.

Reread the Coroutine page. If it’s going into an infinite loop, it’s because you didn’t put a “yield return” statement somewhere important.

1 Like

This definitely sounds like user error. Waiting for some defined time is a common task in Unity, as described by @StarManta . Care to share your problem code?