I want to iterate trougth array of gameobjects and print their names to gui , i do have singleton object which has my array:
Singleton object:
public static var JobBuildings : GameObject[] = new GameObject[1];
I have this code to run trought gameobject array :
for (var Job : GameObject in Var.JobBuildings) {
switch(Job.transform.name){
case "Plant_Wheat" :
print(Job.GetComponent(Crops_Wheat_AI).WorkSlots);
GUI.Label( Rect(10,10,250,80), "Available farm positions: " + Job.GetComponent(Crops_Wheat_AI).WorkSlots);
break;
}
}
But i get this error and i don’t know why ! NullReferenceException: Object reference not set to an instance of an object UserGui.OnGUI () (at Assets/Script/UserGui.js:75)
Yeah we need to see the line in question. Also you really shouldn’t be calling a method from a nullable return type, you’re just asking for a NullReferenceException there.