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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.