- Home /
Deleting all child clones in a GameObject
Like the picture below. How can I delete/destroy all of the Particle(clones) in those GameObjects when I press the "F" button ?
Event Flow: If I click those "GameObj" the "Particle(Clone)" will appear and then if I press the "F" button those clones must/should be deleted/destroyed
Well, it's great to have this image which helps to understand your problem, however there are somethings that aren't clear at all.
What "event" should destroy those gameobjects? Think about your event flow. What happens --> what should happen.
Where are scripts attached which could do this job? On each "GameOgj"? or maybe on a higher parent (if there is any)?
Event Flow: If I click those "GameObj" the "Particle(Clone)" will appear and t hen if I press the "F" button those clones must be deleted/destroyed
Uhm, thanks for the Update, but my second point is still unanswered. I guess you have the "click and create the particle effect" woring. $$anonymous$$y question was how you do this. Where is the script / the scripts attached to? Anyway i'll post a possible answer.
Answer by Bunny83 · Dec 18, 2013 at 07:53 PM
You could do something like that:
// C#
public class SomeObject : MonoBehaviour
{
public Transform particleEffect;
void OnMouseDown()
{
var clone = (Transform)Instantiate(particleEffect);
clone.parent = transform;
clone.localPosition = Vector3.zero;
clone.localEulerAngles = Vector3.zero;
}
void Update()
{
if(Input.GetKey(KeyCode.F))
{
for(int i = transform.childCount-1; i>=0; i--)
Destroy(transform.GetChild(i).gameObject);
}
}
}
Attach this script to all of your "GameObj". If you have a different way of creating the particle effects, please include your script in your question.
thanks for the answer. $$anonymous$$anage to delete all of the child clones using your loop method
Thank you for this, been looking everywhere and couldn't find a solution.
Your answer
Follow this Question
Related Questions
how do you destroy a texture2d array ? 3 Answers
How to destroy GameObject when clicked on. 2 Answers
Detect when GameObject has been deleted / removed from scene 10 Answers
finding and destroying specific children 1 Answer
Destroy all previous clones. 2 Answers