Time for action – pretty maids all in a row

We're going to create a 2D array referencing our squares in an interesting way. Follow along.

  1. Create a standard one-dimensional array to hold the squares by adding this declaration to the GameLogic script:
    var XPiece:GameObject;
    var OPiece:GameObject;
    var currentPlayer:int = 1;
    var prompt:GUIText;
    var aSquares:GameObject[];
    
  2. Select the GameLogic GameObject. Set the Size of the aSquares array to 9 in the Inspector panel.
    Time for action – pretty maids all in a row
  3. One by one, making sure you get all 9 unique squares with no repeats, click and drag the 9 Square GameObjects from the Hierarchy panel into the array slots in the Inspector panel. Another way ...

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.