diff --git a/Game/Assets/Scripts/StartScene.cs b/Game/Assets/Scripts/StartScene.cs index a528819..62c5f16 100644 --- a/Game/Assets/Scripts/StartScene.cs +++ b/Game/Assets/Scripts/StartScene.cs @@ -1,5 +1,6 @@ using UnityEngine; using UnityEngine.SceneManagement; +using System.Collections; public class StartScene : MonoBehaviour { @@ -11,8 +12,20 @@ public class StartScene : MonoBehaviour { if (Input.anyKey) { - mySpeaker.PlayOneShot(jingle); - SceneManager.LoadScene(0, LoadSceneMode.Single); + // Start the "coroutine" instead of switching scenes immediately + StartCoroutine(PlaySoundAndLoad()); } } + + IEnumerator PlaySoundAndLoad() + { + // 1. Play the sound + mySpeaker.PlayOneShot(jingle); + + // 2. Wait for the length of the sound clip (or a fixed time) + yield return new WaitForSeconds(jingle.length - 0.5f); + + // 3. Now it is safe to load the scene + SceneManager.LoadScene(0, LoadSceneMode.Single); + } }