So I have a problem where my game freezes up. I am checking for key presses in update, and setting a variable to know which key was pressed. Then I have another function that continues to check to see the value of said variable. It then determines what to do based on what key you press. So here is my update,
`
void update ()
{
if (Input.GetKeyDown(KeyCode.RightArrow))
KeyPress = "Right";
else if (Input.GetKeyDown(KeyCode.LeftArrow))
KeyPress = "Left";
else if (Input.GetKeyDown(KeyCode.UpArrow))
KeyPress = "Up";
else if (Input.GetKeyDown(KeyCode.DownArrow))
KeyPress = "Down";
else if (Input.GetKey(KeyCode.Return))
KeyPress = "Enter";
else
KeyPress = "";
}
`
and here is my function that responds to the key presses.
`
string Navigate()
{
string choice = "";
int position = 0;
bool done = false;
while (done == false)
{
if (KeyPress == "Right")
{
position++;
}
else if (KeyPress == "Left")
{
position--;
}
else if (KeyPress == "Enter")
{
done = true;
}
if (position < 4)
position = 0;
else if (position > 0)
position = 4;
Debug.Log(position);
}
return choice;
}
`
This is only part of my script, but when I comment out this part it works fine. I have another function that calls Navigate.
Why is this hanging up? I don’t see a problem.