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; var player:int; var gameLogic:GameObject; function Start () { gameLogic = GameObject.Find("GameLogic"); } function OnMouseDown() { if(player == 0) { gameLogic.GetComponent(GameLogic).ClickSquare(gameObject); } }