x


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);

    }

}

more ▼

asked Feb 24 '11 at 04:04 PM

BSVALVE gravatar image

BSVALVE
1 18 20 25

can it be assumed you've assigned your game objects to the array, or is that whats giving you trouble?

Feb 24 '11 at 04:13 PM Alec Slayden

err, Just can't figure out in a moment or 2 lol...

Feb 25 '11 at 01:06 PM BSVALVE
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Feb 24 '11 at 05:20 PM

DaveA gravatar image

DaveA
26.8k 153 171 257

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Feb 24 '11 at 11:26 PM

Grcan SERBEST gravatar image

Grcan SERBEST
71 1 1 7

Thanks again I got this fixed.

Feb 25 '11 at 08:21 AM BSVALVE
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2171
x1725
x1396
x786

asked: Feb 24 '11 at 04:04 PM

Seen: 1529 times

Last Updated: Feb 24 '11 at 04:04 PM