I have done this many times but this time I’m confused. I am using Unity3d 2018.4.3 and I am trying to unlock user controls after beginning audio finishes. I am doing the VERY basic code of Starting a Coroutine to wait and I have tried many iterations.
public void GiveInstructions(AudioClip clip)
{
audioSource.clip = clip;
audioSource.Play();
// another approach (doesn't work) - new WaitForSeconds(clip.length);
StartCoroutine(WaitForAudio(clip));
}
private IEnumerator WaitForAudio(AudioClip clip)
{
// One approach(doesn't work) - yield return WaitUntil(() => audioSource.isPlaying == false);
// Doesn't work - yield return new WaitForSeconds(clip.length);
// Also doesn't work
while (audioSource.isPlaying)
{
yield return null;
}
}
Only thing that remotely works is the following:
void FixedUpdate()
{
if (!audioSource.isPlaying)
{
// Do my thing
}
}
And I am not about to do that hack.
Any help would be great.