Hi. I made a pong game for practice. I added a audio source to the ball to play during collisions and its working. I also added audio source to my MainMenu(empty object) which need to play when I click a UI button. I have Play and Quit button. In Unity Editor, in Game mode, when I press the Quit button, the sound is playing. Play button also has same setup like Quit button, but when I click it, no sound is playing. It successfully loads the Game scene though. So I am guessing that the Game scene loads faster than the sound could play. This is the code for the MainMenu script,
public class MainMenu : MonoBehaviour
{
private AudioSource clickSound;
void Start()
{
clickSound = GetComponent<AudioSource>();
}
public void PlayGame()
{
clickSound.Play();
SceneManager.LoadScene("Game");
}
public void QuitGame()
{
clickSound.Play();
Application.Quit();
}
}
I call the PlayGame() and QuitGame() methods in OnClick settings of the Play button and Quit button respectively. Since its just for practice, I moved on to next practice game. But I need to learn how to do it so I can do it in the next game. Thanks in advance.