- Home /
press key to continue, unity freezes
Sorry, I'm maybe too noob, but I'm making a game, and I want that when the player gets the objetive, it display something like "press space to continue" but when I get the objetive,unity freezes. Maybe I'm doing something too wrong, I don't know, this is the code fragment with the error.
winText.text="You Win! You time is: "+finalTime+" space to continue";
while(true){
if(Input.GetKey(KeyCode.Space))
{
Application.LoadLevel(Application.loadedLevel+1);
}
}
Maybe the while(true) is bad? I need to make a coroutine? I'm not too good with that yet. Thanks, sorry if my english is bad.
Just get rid of the while loop, what do you need it for? and you need to specify which level to load you can't just do loadedLevel+1 you have to specify your scene like: Application.LoadLevel(NextScene);
Yes the 'while(true)' is bad and is what is hanging up your app. I don't know where you have this code, or in what language (C# or Javascript). You can either place the Input.Get$$anonymous$$ey() code in Update(), or you can make the above code a coroutine and yield. But without more code and the language it is written in, I cannot be specific.
Answer by smallbit · Aug 02, 2014 at 03:21 PM
Yes its while true ...
set up a boolean to flag if player gets the "objective" (set gotObjective = true; when player finishes level) and than in update check the key.
bool gotObjective = false;
void Update()
{
if(gotObjective)
{
if(Input.GetKey(KeyCode.Space))
{
Application.LoadLevel(Application.loadedLevel+1);
}
}
}
@leoxs: If your question is answered, would you please mark your question as solved by accepting the answer?
Your answer
Follow this Question
Related Questions
How do I open a GUI on key press? 1 Answer
Cloud recognition in Vuforia 0 Answers
motion detection 0 Answers
Network Programming in Unity 2 Answers
Not able to send message from java to Unity using UnityPlayer.UnitySendMessage 0 Answers