I’m doing something wrong but as this is my first time working with Lists, I don’t know what. My MobSpawner does this
private void SpawnAllMobs() {
for(int mobcnt = 0; mobcnt < mobCount; mobcnt ++) {
GameObject mob = Instantiate(mobPrefabs[Random.Range(0,mobPrefabs.Length)],
transform.position, Quaternion.identity) as GameObject;
// Get rid of (Clone), setup Parent
mob.gameObject.name = mob.gameObject.name.Replace("(Clone)","").Trim();
mob.transform.parent = transform;
mob.gameObject.GetComponentInChildren<QM_EnemyHealth>().myIndex = mobcnt;
mobs.Add(mob);
}
}
and I see my bad guys have a myIndex value of 0,1,2 (where mobCount is 3) - all good there. When bad guy dies it goes into this:
public void RemoveAMob(int listIndex) {
mobs.RemoveAt(listIndex);
}
the myIndex value is passed to listIndex. From that, I’m getting an error Argument is out of range Parameter name: index but not every time. If I kill mob(0) and do this RemoveAt(0), does something happen to mob(1) and (2) in the List?
http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?