Time for action – +9 accuracy
Let's change the code a little so that we can put the X at the same place as the square that was clicked.
Change this line in the Square
script:
gameLogic.GetComponent(GameLogic).ClickSquare(gameObject);
Modify the following ClickSquare
function in the GameLogic script:
function ClickSquare(square:GameObject) { Instantiate(XPiece, square.transform.position, Quaternion.identity); }
Delete the print statement we had in there earlier.
Instead of passing the x
and y
values of Square
to the ClickSquare
function, we're passing a reference to the entire Square
GameObject itself, with the reference name lowercase-s square
. (Remember that Unity JavaScript is case-sensitive, so Square
is not the same animal as square
).
Test the game, and click on the Squares. Now the X's are all falling in their proper places as you click on the different Squares, as shown in the following screenshot: