sound (need fix)
This commit is contained in:
@@ -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)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user