From 4f93081d97b55e06e37fefe4df22f7a772457dd7 Mon Sep 17 00:00:00 2001 From: orsolya-st Date: Sat, 6 Jun 2026 22:59:44 +0200 Subject: [PATCH] sound (need fix) --- Game/Assets/Scripts/StartScene.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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); + } }