Read after thinking

One of the crucial pieces of information we're missing is which player's piece is inside each square. Thanks to the isUsed boolean, we know when a square has a piece in it, but we have no idea which piece it is. Keeping better track of which piece occupies which square is the first step to detecting a win condition.

isUsed isn't a very information-packed variable. By replacing it with an int, we can use it to store more valuable data.

In the Square script, replace this:

var isUsed:boolean;

with this:

var player:int;

In the logic check, change this:

if(!isUsed)

to this:

if(player == 0)

and remove this line from the OnMouseDown function:

isUsed = true;

Altogether, the Square script should look like this:

#pragma strict var x:int; var y:int; ...

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.