Wylie
1
How do I script it (in a two player game where both players alternate using the mouse for one click at a time) so that after the first player clicks, the second player can't click until he or she presses a button on the keyboard, and then after he clicks, the first player has to press another button on the keyboard.
How can I do this without resorting to loading separate levels each time a player clicks? I would prefer them to see the screen at all times.
I imagine you could do something similar to this (in a C# MonoBehaviour-derived class):
bool clicked = false;
bool pressedButton = false;
void Update()
{
if (Input.GetMouseButtonUp(0))
clicked = true;
if (clicked && Input.GetKeyDown(GetPlayerButtonName()))
pressedButton = true;
if (clicked && pressedButton)
{
clicked = false;
pressedButton = false;
SwitchPlayer();
}
}
`GetPlayerButtonName()` would return the name of the keyboard button that the other player is required to press after the current player clicks.
Hope this helps.