I’m trying to create an object add a variable and add it to a list, but Unity seems to make a very simple thing very hard to do. I’ve tried every example in the manuals and forums but still can’t get it to work.
void Start () {
GameObject pl1 = Instantiate(Resources.Load("Planet"),new Vector3(0,0,0),Quaternion.identity) as GameObject;
Planet pl = pl1.GetComponent<Planet>();
pl.planetName = "Earth";
planetList.Add(pl1);
}
I get NullReferenceException: Object reference not set to an instance of an object when doing pl.planetName