- Home /
How would I add a scene delay timer to my script?
It is an on click button to change to the next scene. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class Pressstart : MonoBehaviour {
public void PressStart(string CharacterSelect)
{
SceneManager.LoadScene(CharacterSelect);
}
}
Comment
you should put it in the update method I guess.some thing like this
public bool waitToLoadTheScene;
public float timer;
void Update(){
if(waitToLoadTheScene){
timer+=Time.deltaTime;
if(timer > 5) {
Scene$$anonymous$$anager.LoadScene("SceneName");
}
}
}
public void PressStart()
{
waitToLoadTheScene=true;
}
would that affect the on click event I setup?
just a little in script
you can use something like this.
public string sceneName="SceneTwo";
Scene$$anonymous$$anager.LoadScene("sceneName");
Answer by Larry-Dietz · Jan 01, 2018 at 07:01 AM
Why not use a coroutine for this?
Something like this...
public class Pressstart : MonoBehaviour {
public void PressStart(string CharacterSelect)
{
StartCoroutine(LaunchScene(CharacterSelect));
}
IEnumerator LaunchScene(string CharacterSelect){
yield return new WaitForSeconds(5f);
SceneManager.LoadScene(CharacterSelect);
}
}
This would load the scene 5 seconds after pressing the button. Just change the 5f to whatever delay amount you want.
Hope this helps, -Larry