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, ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.