Nice moves

It seems simple enough to create an int variable to keep track of the number of moves that have been made, which we'll increment every time a player places a piece. If we're up to the ninth move with no winner, that means all of the squares have been filled and we've reached a stalemate.

At the top of the script, declare a moves variable:

var gameIsOver:boolean;
var moves:int;

Just above the Instantiate command in the ClickSquare function, increment moves:

moves ++;
Instantiate(piece, square.transform.position, Quaternion.identity);

Tack on an else to the CheckForWin condition check that ends the game if we've reached 9 moves with no winner:

if(CheckForWin(square))
{
  gameIsOver = true;
  ShowWinnerPrompt();
  return;
} else if(moves >= 9) ...

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.