- Home /
Multidimensional GameObject Arrays
Hi - so i'm having a problem with my multidimensional array.
I need to sort my field in an array sorted by: rows[]
rows[0] = gameTile[1,2,3,4,5,6];
rows[1] = gameTile[1,2,3,4,];
And so on.
This is the code:
function OnLevelWasLoaded()
{
levelWon = false;
temporaryGameTiles = GameObject.FindGameObjectsWithTag("Game Tile");
temporaryRows = GameObject.FindGameObjectsWithTag("Row");
temporaryStartIndicators = GameObject.FindGameObjectsWithTag("Start Indicator");
touchIndicator = GameObject.Find("Touch Indicator");
for(var v=0; v < temporaryRows.length; v++)
{
var a = v+1;
//gameTiles[v] = new Array();
//var gameTiles : GameObject[];
for(var u=0; u <temporaryGameTiles.length; u++)
{
for(var i=0; i < temporaryGameTiles.length; i++)
{
var b = u+1;
if(temporaryGameTiles[i].transform.name == "Game Tile "+a+"."+b)
{
rows[v,u] = temporaryGameTiles[i];
}
}
}
}
my row variable is defined as: var row : GameObject[,];
The error i get is: NullReferenceException: Object reference not set to an instance of an object GameScript.OnLevelWasLoaded () (at Assets/Scripts/GameScript.js:96)
Theres nothing wrong with temporaryGameTile[i]; i have debugged this many times.
Please help :D
Answer by DaveA · Aug 30, 2011 at 04:17 PM
If you declare the row as GameObject[,], you must also allocate it (in Start or Awake) like row = new GameObject[4,6] or something.
Your answer
Follow this Question
Related Questions
Null reference when accessing GameObject in the Array(C#) 1 Answer
Access System.Serializable class from script? 1 Answer
NullReferenceException: Object reference not set to an instance of an object 1 Answer
NullReference when accessing GameObject in array (C#) 1 Answer
Split() into a fixed length array? 1 Answer