Hi, i am writting simple card game just to learn programming and i have been wondering how to wait in application for user to click button.
The idea is that i start the game and draw cards - but after that i want to give user choice to redraw cards- so i show gui buttons. But the problem is that the code continues to execute or when i make infinite loop unity freezes.
//PlayerTurn function
void PlayerTurn(){
isPlayerTurn = false;
//Check if is first turn
if (isFirstTurn == true) {
//Draw cards
FirstDraw();
ShowRedrawButtons = true;
//Wait here for user input
//while (ShowRedrawButtons == true){
//}
isFirstTurn = false;
}
//PlayerHand.Add(DrawCard());
for(int i = 0;i <= PlayerHand.Count - 1;i++){
Debug.Log((string)PlayerHand[i]);
}
}
and this is my OnGUI Function
void OnGUI(){
if (ShowRedrawButtons == true) {
if (GUI.Button (new Rect (Screen.width / 2 - 110, Screen.height / 2, 100, 50), "Redraw")) {
Redraw ();
ShowRedrawButtons = false;
}
if (GUI.Button (new Rect (Screen.width / 2 + 110, Screen.height / 2, 100, 50), "Don't Redraw")) {
ShowRedrawButtons = false;
}
}
}
In line 12-13 if i uncommet the application freezes. I have no idea how to achieve this in other way. I call PlayerTurn in update function