Hello again,
Since from my last question, with your help i managed to delete all of my instances with one click! That’s great! Now i would like to develop something more on to this. So here is what i would like to do; naming each ten copies of clones as clone1, clone2, clone3 etc and deleting these ten copies of clones in order to their names so first clone3 will be deleted then clone2 and clone1 etc. I managed to do it by using tags and searching for the tags and destroying them but this seemed really long to me. So is there any alternative that you could possibly suggest? Thank you in advance and here is the script that i’ve written.(Excuse me for my english and grammar since i am a foreigner)
#pragma strict
var Reference : GameObject;
private var Clones : Array = new Array();
function Start ()
{
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.C))//C stands for creating 10 clones of reference
{
for(var i : int = 0; i < 10; ++i)
{
var Clone : GameObject;
Clone = Instantiate(Reference, Reference.transform.position, Reference.transform.rotation);
Clone.name = "Clone";
Clones.Push(Clone);
}
}
if(Input.GetKeyDown(KeyCode.D))//D stands for deleting clones from the scene
{
for(var j : GameObject in Clones)
{
Destroy(j);
}
Clones.Clear();
}
}