Time for action – designer to player. Come in, player.
Most people over the age of zero know how to play Tic Tac Toe, but just to be safe, let's rig up a down-and-dirty onscreen prompt to let the players know whose turn it is.
Create a new GUI Text.
Position it at
0
,1
,0
with a font size of36
.Rename it as
Prompt
.Store a reference to it in the
GameLogic
script:var XPiece:GameObject; var OPiece:GameObject; var currentPlayer:int = 1; var prompt:GUIText;
Save the script.
Select the
GameLogic
GameObject.Drag the
Prompt
GUIText GameObject into theprompt
variable ofGameLogic
in the Inspector panel.Back in the
GameLogic
script, create a function, as follows, to show the players whose /turn it is:function ShowPlayerPrompt() { if(currentPlayer == 1) { prompt.text = "Player 1, place an X."; } else { prompt.text = "Player 2, place an O."; } }
Call this function at the beginning of the game, and again after a move is made.
function Start () { ShowPlayerPrompt(); }
and later:
function ClickSquare...