Wait Until Press a Button
Hi,
I make a turn-based strategy game, and the problem is when one player attack the other one, the player able to support them, thats why i make a panel where player can choose the supported player. and i want to wait until to choose and continue the game after it. I have have never use coroutines or yield.
thanks
Answer by ZefanS · Jan 13, 2016 at 08:16 AM
If you're using JavaScript it's pretty straight forward:
#pragma strict
public var buttonPressed : boolean;
function ChooseSupportedPlayer()
{
buttonPressed = false;
//Do some stuff like present the button to the player
while (buttonPressed == false)
{
//Wait for the button to be pressed
yield;
}
//Continue with more stuff after the button has been pressed
}
function Button()
{
buttonPressed = true;
}
Button() will need to be assigned to the OnClick() listener of the button in the inspector. If you are using C# the syntax is slightly more complicated because you need to use an IEnumerator, but the general idea is the same. Here's the reference page.
Hope this helps!
Your answer
Follow this Question
Related Questions
Wait inside a non void method 1 Answer
CharacterInfo.glyphWidth always 0 2 Answers
Scaling an image sent to UI Image 0 Answers
One textUI and two colliders that update it 0 Answers
Refresh Chat room messages 1 Answer