Time for action – it's hip to be square
The way that players interact with a Tic Tac Toe is to place an X or an O piece in the empty spaces on the grid. If we create an invisible, clickable GameObject to sit in those spaces and respond to clicks, we'll have nailed down most of the game's interactivity. Follow these steps to create that clickable square:
Create a cube. Position it at
-2.8
,1
,-19.7
with a scale of4.2
,1
,4.2
. This puts the square in the top-left cell of the grid, sized appropriately.Rename it
Square
.Create a new Javascript and rename it
Square
.Drag the
Square
script onto theSquare
GameObject.Add this to the
GameLogic
script:function ClickSquare(x:int, y:int) { print("Square " + x + "," + y + " was clicked"); }
Double-click to open the
Square
script and punch in this code:#pragma strict var x:int; var y:int; var gameLogic:GameObject; function Start () { gameLogic = GameObject.Find("GameLogic"); } function OnMouseDown() { gameLogic.GetComponent(GameLogic).ClickSquare...