I’m instantiating multiple instances of a prefab that has a “Hut” script attached to it. The Hut script has a public int called TESTID.
public class test : MonoBehaviour {
public GameObject Hutprefab;
private int tstID = 0;
public List<GameObject> hutList = new List<GameObject>();
public void CreateHut()
{
GameObject newhut = Hutprefab;
Instantiate (newhut, transform.position, Quaternion.identity);
hutList.Add (newhut);
newhut.GetComponent<Hut> ().TESTID = tstID;
tstID++;
}
}
The instantiating works fine, each new gameobject has a new TESTID. But when I try to add them to a list, the list grows by one but also overwrites every item in the list with the newest one.