- Home /
Null reference at for loop (list)
Hello everyone, I have a little problem with Unity GUI I think. I try to show some strings and Texture2D stocked in a List of class. Here's the code :
void OnGUI () {
if(journalOpen){
GUI.Label(new Rect(Screen.width - journalBackground.width - 50, 50, journalBackground.width, journalBackground.height), journalBackground);
DisplayEvidences();
}
}
void DisplayEvidences(){
for(int i=0; i <= evidences.Count; i++){
GUI.Label(new Rect(Screen.width - journalBackground.width - 150 - evidences[i].icon.width + (i* texteW),50,evidences[i].icon.width,evidences[i].icon.height), evidences[i].icon); //null reference
for(int j=0; j <= evidences[i].textes.Length; j++){
GUI.Label(new Rect(Screen.width - journalBackground.width - 100 - evidences[i].icon.width + (i* texteW),50 + (j* texteH),150,25), evidences[i].textes[j]);
}
}
}
evidences is just a list of evidences_class that contain a string[] and a Texture2D. It's probably a rookie mistake but I can't figure it out. Thanks !
EDIT : Now I have an Index Out of Range on the second for loop. Maybe something with the array of string from the class ?
Have a look at my resource for hunting null reference exceptions. $$anonymous$$aybe it'll help. It's located here
Thanks ! I just found something with your help. Now I have an Index out of range. Array index on the second for loop.
Thanks a lot. I guess this + the help from Jamora fix it. Thank you guys !
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating a custom inspector utilizing a list of class instances with serialization? 1 Answer
Displaying list in UI 2 Answers