Hi, I’m getting this error with this script:
NullReferenceException: Object
reference not set to an instance of an
object WorldUI.Start () (at
Assets/scripts/WorldUI.cs:17)
I’ve read, tha this occurs, if The calss Buildings doesn’t contain MenuIcon, but as you can see, the script includes sthis.
WorldUI:
using UnityEngine;
using System.Collections;
public class WorldUI : MonoBehaviour {
void Start () {
string path = "Buildings/";
Object[] Buildings = Resources.LoadAll(path);
if(Buildings.Length > 0) {
for(int i =0; i < Buildings.Length; i++)
{
GameObject build = Buildings *as GameObject;*
Texture2D Icon = build.GetComponent().MenuIcon; =====LINE 17=====
// Texture2D IconRo = build.GetComponent().MenuIconRo;
// Debug.Log(Buildings*);*
MenuSetup.UnitIconTextures.Add(Icon);
// MenuSetup.UnitIconTexturesRo.Add(Icon);
MenuSetup.UnitNames.Add(build.name);
MenuSetup.UnitPaths.Add(path+“/”+build.name);
}
}
}
}
Building
using UnityEngine;
using System.Collections;
public class Building : MonoBehaviour {
public Vector2 ScreenPos;
public bool OnScreen;
public float team; // 0 = spieler; 1 = gegner
public bool Selected = false;
public float HP = 100f;
public float Reload = 10f;
public float Range = 40f;
public bool Alive = true;
public bool Selectable = true;
public Texture2D MenuIcon; ======HERE=======
public Texture2D MenuIconRo;
}
I hope you can help me here