Files
DropToTheRoots/Game/Assets/Scripts/StartScene.cs
T
2026-06-07 03:45:52 +02:00

32 lines
773 B
C#

using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
public class StartScene : MonoBehaviour
{
public AudioSource mySpeaker;
public AudioClip jingle;
// Update is called once per frame
void Update()
{
if (Input.anyKeyDown)
{
// 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(0.4f);
// 3. Now it is safe to load the scene
SceneManager.LoadScene(0, LoadSceneMode.Single);
}
}