I have a Button in which I have linked on the OnClick a function to load and Scene:
But I want also to have Sound when I click on the same button, so I have created an AudioSource, so again on the OnClick I have added another call for the AudioSource.Play
This works if don’t execute my function that LoadScene, but when I have both of them on OnClick I’m not able to listen the sound.
Do you know if I’m missing something to get this working?
Thanks in advance
The sound is being cut off, because the script will load the next scene at the same-time. You can delay the scene load with a coroutine, replace the line where you have
SceneManager.LoadScene(1) with this:
The coroutine can wait for a specified time, or if you have the AudioClip, you can instruct it to wait for the length of the sound instead.
yield return new WaitForSeconds(1.0f);
thanks bro, that really helped me @Jessespike