- Home /
How can I destroy objects and instantiates new in Array?
Hi All Unities, How can I destroy objects and instantiates new in Array? Please help!
var Speech:GameObject[];
function Start () { Instantiate(Speech[0], transform.position, transform.rotation); }
function Update(){ if(Input.GetMouseButtonDown(0)){ Instantiate(Speech[1], transform.position, transform.rotation);
}
}
can it be assumed you've assigned your game objects to the array, or is that whats giving you trouble?
Answer by DaveA · Feb 24, 2011 at 05:20 PM
Not quite sure what you are asking, but if it's 'How can I destroy these object I instantiate like this?' then you would assign the return of 'Instantiate' to some variable (probably another array). Then destroying the array, or destroying elements in the array, would destroy those objects.
Answer by Grcan SERBEST · Feb 24, 2011 at 11:26 PM
Hello unity4dNoob,
Can you use Speech[0]'s object again? If you use Speech[0]'s object again You should appoint Speech[0]'s object to an interim value. Else you are requests access to Speech[0]'s object again. You can not access to deleted objects.
If you not use Speech[0]'s object. You can destroy easly with this code
var Speech : GameObject[];
function Update () {
if(Input.GetMouseButtonDown(0)){
Destroy(Speech[0].gameObject);
}
}
Regards Grcan