- Home /
C# How do i destroy all of my instantiated clones?
Hello everyone. I'm trying to destroy all of my clones with the for loops that were recommended by others questions, and Answers.
But I just can't seem to get it right, I believe most of them are in Java Script and I don't really know how it works for javascript and my entire scripts are C#. So it confuses me.
If anyone know how to do this with C# please let me know. I'm kind of confused.
Fappp's answer is incomplete. But so is your question.
Since you already have some code, post it! Do you already have an array of clones? Of what type are your clones?
And also, if you want to pursue a career in Unity3D, change to C# as soon as you can. Professionals work with C#.
Thanks for clearing that up! I don't really believe C# is for professionals. C++ is. But most likely pro's who are capable of writing C++ are not bound to Unity.
Also I've never ran into anything that couldn't be done with Unity JavaScript :) It's different, yes... Better or worse, no...
Well then, it's a good thing I'm currently using C# then Haha, I started out with C# ever since I watched that 2D Character tutorial video from Unity. Haven't stopped since.
But anyways sorry about the late reply everyone.
I got it working thanks to Galshal's answer.
Thanks for the help Fappp and Galshal, the Lists really did make it easier and I got it going smoothly now.
: )
@Fappp - I am a professional freelance developer and I worked on multiple successful mobile and Facebook games - built in Unity. The reason I say professional is because in the industry, when companies use Unity (and yes they do, trust me), they always use C#, never UnityScript. You can Google why, or just accept it for now and find out later why. C++ is a completely different language, and yes, also used in the industry environment.
I meant no offence, but again, if you're looking for a career as a Unity3D developer, learn how to use C#.
Answer by galshal · May 06, 2015 at 04:17 PM
first of all , are the instanitated GameObjects are in a dictionary or List because then running all of them and distroying them will be very easy, if not you should do that, i recomment a list.
second you should run that list in somthing like this:
(lets call the gameObjects list monstersList)
foreach (GameObject monster in monstersList){
GameObject.Destroy(monster);
}
Answer by Dubtoker · Dec 09, 2016 at 06:18 AM
Just give them all a tag , then Destroy all game objects with tag....??? This should work I think, not tested!
Answer by Fappp · May 06, 2015 at 04:03 PM
I'm pretty much a JavaScript type myself, but this should be the correct looping in C#.
for ( GameObject i = 0; i < clones.Length; i++ ){ GameObject.Destroy(clones[i]); }
Your answer
![](https://koobas.hobune.stream/wayback/20220613194931im_/https://answers.unity.com/themes/thub/images/avi.jpg)