Time for action – score!

Because the solution requires two functions that each need to access the lists of win and block opportunities, those lists need to be defined at the top of the code as member variables that any function can access:

 var aGrid:GameObject[,];
  var gameIsOver:boolean;
  var moves:int;
  var aBlockOpportunities:List.<GameObject>;
  var aWinOpportunities:List.<GameObject>;

This is the combined WinOrBlock function:

function WinOrBlock():GameObject
{
  aBlockOpportunities = new List.<GameObject>();
  aWinOpportunities = new List.<GameObject>();
  // Empty out these lists before we start searching.
  // Check the rows for 2 in a row:
  CheckFor2InARow([Vector2(0,0), Vector2(1,0), Vector2(2,0)]);
 CheckFor2InARow([Vector2(0,1), Vector2(1,1), ...

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.