- Home /
[C#] Do not load scene yet
Hey, so I have a bit of a difficult one here, I have tried looking around but no option has appeared to work as of yet. I was hoping you could help me!
Basically I have a scene of which you enter a collider then a sound will play, it all works fine but then I thought "ok let's load a new scene after the sound". I thought simply using SceneManager would work but it does not as it just loads the scene immediately.
I just need the new scene to not load until the audio clip has finished.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Gun : MonoBehaviour {
public AudioClip Gunfight;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player") // Add another if statement for button press.
{
AudioSource.PlayClipAtPoint(Gunfight, transform.position);
{
SceneManager.LoadScene("14"); // Only if AudioSource has finished!
}
}
}
}
To answer any questions. There are no errors here I just need a new line added so the scene does not load immediately. Thanks for the help, very much appreciated! :D
Answer by srikaran_p · Sep 17, 2016 at 07:34 AM
Well, you must be knowing how long the audio plays. You can use a coroutine to wait for the amount of seconds and then load the scene which you want load. Well, even I'm not an expert in Unity yet but a easy and long solution. Don't worry it is not too long.
Your answer
![](https://koobas.hobune.stream/wayback/20220612092853im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
put a void in an if statement? 1 Answer
An OS design issue: File types associated with their appropriate programs 1 Answer
Blocking level progression. 1 Answer