Wait 2 seconds in Update
I want to wait 2 seconds before I load a new Scene.
public float CurrentScale;
public float EndScale;
public float CurrentPosition;
public float EndPosition;
public float NurEinmalStart;
public float NurEinmalEnde;
// Use this for initialization
void Start () {
EndScale = 5;
CurrentScale = 1;
EndPosition = 35;
CurrentPosition = 0;
NurEinmalStart = 0;
NurEinmalEnde = 1;
}
// Update is called once per frame
void Update () {
if (CurrentScale < EndScale) {
CurrentScale = CurrentScale + 0.03f;
} else {
if (NurEinmalStart < NurEinmalEnde) {
this.transform.position += new Vector3 (0, 0, 9);
NurEinmalStart = 1;
}
if (CurrentPosition < EndPosition) {
this.transform.position += new Vector3 (0, 0.2f, 0);
CurrentPosition = CurrentPosition + 0.2f;
} else {
this.transform.position += new Vector3 (0, 0, -9);
//<--how to wait for 2 seconds?
Application.LoadLevel (1);
}
}
}
,
Comment
Answer by jasonlu00 · Sep 03, 2017 at 04:35 AM
Use coroutine:
private IEnumerator DelayLoadLevel()
{
yield return new WaitForSeconds(2f);
Application.LoadLevel(1);
}
and replace your Application.LoadLevel(1); with StartCoroutine(DelayLoadLevel());
what would 'yield return new waitforseconds' be in javascript? is it just yield waitforseconds?