Click-spamming for fun and profit

The human player can also cheat, and place an X during the pause while the computer is "thinking". Try "click-spamming" the grid to place more Xs than you ought to. If you're very quick, you can fill the grid with Xs before the computer places a single O.

By adding a conditional check to the ClickSquare function, we can make sure the human can only place a piece when it's his or her turn:

function ClickSquare(square:GameObject)
{
  if(gameIsOver || currentPlayer == 2) return;

The double-pipe means "OR". If either of the statements separated by || in the conditional check resolve to true, then the code within the conditional is executed.

So if the human clicks to place a piece, if either the game is over or it's the ...

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.