Clean-up on aisle code

It's more succinct than it was, but this code is still a nightmare to read and update. Let's try to refactor it a little more.

There's a lot of GetComponent.<Square>().player happening throughout the line. What if we made one function that would do that job, just to shorten up our code and make it a little more readable?

By setting up a function that accepts x and y as arguments, and spits out the value of a square's player variable, we'll have a handy and reusable piece of code for all kinds of situations. You should start writing the code into your project again.

function GetPlayer(x:int, y:int):int
{
  return aGrid[x,y].GetComponent.<Square>().player;
}

What just happened – vending machine

Just like our vending machine analogy ...

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.