- Home /
Question by
BloodBTF · Jul 05, 2016 at 08:29 PM ·
scripting problemaudiosourcebooleanmusic
How to check if a audio clip had ended via scripting?
I have a set of music tracks in my project and I want them to play a random track every time the previous one has ended. (Like the method EA uses). I know I need to use Random.range to play random tracks, but I want to check if one has ended before the other starts playing. Is there a static Boolean I don't know from the AudioSource class that does this?
Comment
Answer by LiterallyJeff · Jul 06, 2016 at 07:28 PM
You can check AudioSource.isPlaying each frame to know if a clip is still playing or not. Otherwise you can use AudioSource.clip.length as an amount of time to wait before moving on, perhaps using a coroutine WaitForSeconds, or using timestamp comparison each frame.