Question by
sebastardo · Jul 05, 2017 at 04:02 AM ·
c#keydown
C# Load Level after seconds+key press
i Want to change level on keypress and after X seconds I dont know why " yield WaitForSeconds " do not work
Here's my script
using UnityEngine;
using System.Collections;
public class Cambiar_nivel : MonoBehaviour
{
void Update()
{
//Load a scene by the name "SceneName" if you press the W key.
if (Input.GetKeyDown(KeyCode.W))
{
yield WaitForSeconds (5);
Application.LoadLevel("2");
}
}
}
Comment
Answer by TroubledMagician · Jul 05, 2017 at 11:17 AM
You're missing "return new", so "yield return new WaitForSeconds (5);", also, it must be inside a method of type IEnumerator (instead of void) and you must call it with StartCoroutine(Method());
Your answer
Follow this Question
Related Questions
Directory.getFiles() Not working in build 1 Answer
Inventory -Argument is out of range - Diagnostics to be done 1 Answer
Crashing and dont know why 0 Answers
Random Generation (Dungeon) with improvements in mind. 0 Answers
Beginner question, why goodValue does not return anything? already assigned text 0 Answers