sound (need fix)

This commit is contained in:
orsolya-st
2026-06-06 22:59:44 +02:00
parent b54048370e
commit 4f93081d97
+15 -2
View File
@@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using System.Collections;
public class StartScene : MonoBehaviour public class StartScene : MonoBehaviour
{ {
@@ -11,8 +12,20 @@ public class StartScene : MonoBehaviour
{ {
if (Input.anyKey) if (Input.anyKey)
{ {
mySpeaker.PlayOneShot(jingle); // Start the "coroutine" instead of switching scenes immediately
SceneManager.LoadScene(0, LoadSceneMode.Single); 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);
}
} }