Jump to content

GAME CONCEPT Help :)

- - - - -

  • Please log in to reply
No replies to this topic

#1
photoScan

photoScan

    Newbie

  • Members
  • Pip
  • 5 posts
Getting some Null Reference Exception run-time errors. I do not know why.



public class MyArray

{


public static int[ ][ ] IndexAndColor = new int[7][]; // our jagged array



void Start()

{

                                for (int i = 0; i < 7; i++) 

		{

			

			IndexAndColor[i] = new int[3];

		}

		

		for (int i = 0; i < 7; i++) 

		{

			IndexAndColor[i][0] = 1;

			IndexAndColor[i][1] = 0;

			IndexAndColor[i][2] = 0;

		}


             Debug.Log(IndexAndColor[0][0]); // should be 1, but instead shows a run-time error.

}




There are seven game objects that have their own assigned index from [0,7). Each game object has three states that can be changed by the user.

// Based on certain conditions:
IndexAndColor[5][1] = 0;

This statement should assign the 5th game objects second color to 0 (false)

// Based on certain conditions:
IndexAndColor[5][2] = 1;

This should assign the 5th game objects thrid color to true. I can't use mixed types in a jagged array, so I am using 0 for false, and 1 for true.


if (IndexAndColor[5][1] == 1) 

{

     // change the game object's color

}


if (IndexAndColor[5][2] == 1)

{

    // change the game object's color

}


// ...



But like I said, I am getting null reference exception errors..

Edited by photoScan, 26 September 2010 - 12:12 PM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users