- Home /
UI Button: one action after other with only one click
Hi, my name is Roberto. I'm new using Unity and I learnt how to load a new scene after clicking a button using Scene manager (my level of code is very low, I'm an artist).
Now I would like the same, when you click on that button it load a new scene, but before of that, I would like to play a short audio clip.
If I configure the UI Button with two OnClick events, one pointing to an Audio source and the other to the Scene manager, the sound starts but cannot finish correctly because the game already loaded the new scene.
So, anyone can help me with this?
Thanks in advance.
PS: Sorry for my English, it's not my native language, I hope you could understand the message.
Answer by warrencwwong · Jul 07, 2019 at 07:04 AM
To do this, you should add a delay before the scene changes; You should put this method in you on click.
public void PlayAudioAndChangeScene() { Invoke("ChangeScene", 2); audiosource.play();
} void ChangeScene() { SceneManager.LoadScene(...); }