Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Add/Removing Child objects from a list?

$
0
0
Apparently in order to move multiple instantiated objects, they need to be in a list. Which is great and all. But I have 0 clue how to do such a thing and any attempt at searching for a decent answer leads to the MSDN page which shows a terrible way to list. Well it's terrible in the sense that it's impossible to understand for newer people. So here is my question: How do you do such a thing? So using that link that was provided. I came up with the following: public void PlatformAdd() { pList.Add (PlatformOBJChild); } public void PlatformRemove() { pList.Remove(PlatformOBJChild); } if (MaxCount < 11) { PlatformOBJChild =Instantiate(PlatformOBJSel, new Vector3(1.0f+ iX,1.0f+iY,0.0f), Quaternion.identity) as Transform; iX +=Random.Range(3.0f,6.0f); iY +=Random.Range(1.0f,2.0f); MaxCount++; Debug.Log("MaxCount " + MaxCount); PlatformAdd(); } void OnCollisionEnter(Collision other) { if (PlatformDestroyed == true) { return; } if (other.collider.tag == "Platform") { ss.PlatformRemove(); Destroy(other.gameObject); Destroy(gameObject); PlatformDestroyed = true; } if (other.collider.tag == "PlatformEnd") { Destroy(gameObject); Debug.Log("Platform reached END"); PlatformDestroyed = true; } else { return; } } The problem I am having now is that it deletes the object and then there is a Missing(TransformObject) in the List array. How is this fixed? Or what else can I do to fix this?

Viewing all articles
Browse latest Browse all 171066

Trending Articles