- Home /
This question was
closed May 25, 2014 at 09:09 PM by
tanoshimi for the following reason:
The question is answered, right answer was accepted
Question by
Le-Capitaine · May 25, 2014 at 08:42 PM ·
c#nullreferenceexceptionobject-reference-not-set
An object reference that seems pretty set-to-an-instance-of-an-object to me
Here's all of the relevant and semi-relevant code:
public string[] options;
public string[] optionNames;
public List<GameObject> menus;
GameObject[][] subMenus;
GameObject[,] menuText;
int menu = 0;
int holdCounter;
float oneFrameAgo;
GameObject cursor;
int[] selected;
void Awake () {
menuText = new GameObject[100,100];
MakeSubmenuOf (options, optionNames, this.gameObject, 0, 20, 0.5f, 0.5f, 0.7f);
cursor = new GameObject ("Pause Cursor");
cursor.AddComponent<GUIText>();
cursor.transform.parent = this.gameObject.transform;
this.gameObject.SetActive (false);
}
void Update () {
cursor.guiText.color = Color.red;
//-----------------------
cursor.transform.position = menuText[menu,selected[menu]].transform.position + Vector3.forward * 0.02f;
//-----------------------
cursor.guiText.text = menuText[menu,selected[menu]].guiText.text;
cursor.guiText.alignment = menuText[menu,selected[menu]].guiText.alignment;
cursor.guiText.anchor = menuText[menu,selected[menu]].guiText.anchor;
cursor.guiText.font = menuText[menu,selected[menu]].guiText.font;
cursor.guiText.fontSize = menuText[menu,selected[menu]].guiText.fontSize;
}
public void MakeSubmenuOf(string[] menuToMake, string[] niceNames, GameObject parent, int number,
int fontSize, float x, float y, float offsetBetween) {
GameObject subMenuToMake = parent;
for (int i = 0; i < menuToMake.Length; i++) {
menuText[number,i] = new GameObject(menuToMake[i]);
menuText[number,i].transform.position = new Vector3(x,y - (i * offsetBetween), 0);
menuText[number,i].transform.parent = subMenuToMake.transform;
menuText[number,i].AddComponent<GUIText>();
menuText[number,i].guiText.text = niceNames[i];
menuText[number,i].guiText.alignment = TextAlignment.Center;
menuText[number,i].guiText.anchor = TextAnchor.MiddleCenter;
menuText[number,i].guiText.fontSize = fontSize;
}
subMenus [number] = new GameObject[menuToMake.Length];
}
I marked the line at which I get an NRE. I don't know what to think.
Comment
There js LOT of dereferncing going on in that line check ALL of the following individually for non null values:
cursor
menuText
selected
menu
selected[menu]
menuText[menu,selected[menu]]
Follow this Question
Related Questions
My Project doesn't work - Generic.List throws NullReferenceException ?! 0 Answers
Nested Class Initialization 1 Answer
Can't explain an NRE 0 Answers
Trouble with Null Reference in Script 2 Answers