So I am trying to update the variable position when you press a key. I am handling the keypress in update, and the position variable elsewhere. The second functions is called from a string of other functions. KeyPress is a private string. Position is not updating.
`
void update ()
{
if (Input.GetKey (KeyCode.RightArrow))
{
KeyPress = "Right";
}
else if (Input.GetKey (KeyCode.LeftArrow))
{
KeyPress = "Left";
}
else if (Input.GetKey (KeyCode.UpArrow))
{
KeyPress = "Up";
}
else if (Input.GetKey (KeyCode.DownArrow))
{
KeyPress = "Down";
}
else if (Input.GetKey (KeyCode.Return))
{
KeyPress = "Enter";
}
else
{
KeyPress = "";
}
}
`
`
IEnumerator Navigate()
{
int position = 0;
bool done = false;
while (done == false)
{
Debug.Log("In While");
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);
yield return new WaitForFixedUpdate();
}
}
`