- Home /
Question by
overallduka · Feb 13, 2014 at 08:35 PM ·
rigidbodydestroyloop
Destroy dont work on Rigidbody2D
Hello, im try destroy some objects who have created and put in a List, are clones, this is the code:
(method Start)..
StartCoroutine ("Spaw");
}
IEnumerator Spaw(){
if(list == null) list = new List<Rigidbody2D>();
float waittime = Random.Range (minTimeBetweenSpawns, maxTimeBetweenSpawns);
yield return new WaitForSeconds (waittime);
float posY = Random.Range(minSpawnPosY, maxSpawnPosY);
float posX = Random.Range (-11,11);
Vector3 spawnPos = new Vector3(posX,posY, transform.position.z);
Rigidbody2D propInstance = Instantiate (plataforma, spawnPos, Quaternion.identity) as Rigidbody2D;
list.Add (propInstance);
StartCoroutine (Spaw());
if (list.Count >= 3) {
Debug.Log("A conta e de "+list.Count);
foreach(Rigidbody2D rigid in list){
**Destroy(rigid);**
}
list = null;
list = new List<Rigidbody2D>();
}
}
the basic is the Destroy(rigid) and the DestroyImmediate method i try put also, but in the Game dont remove anithing, please, what i make wrong ? Thanks much.
Comment
Best Answer
Answer by robertbu · Feb 13, 2014 at 08:45 PM
Your code is attempting to destroy the Rigidbody component, not the game object. Try:
Destroy(rigid.gameObject);
Your answer
Follow this Question
Related Questions
Deleting GameObjects 1 Answer
Destroy Enemy Rigidbody after Jumping on Head? 3 Answers
Trying to not make an infinite loop 0 Answers
Why doesn't this script work?? Please help.. 1 Answer
How do you find out what connectedBody, a Rigidbody belongs to? 0 Answers