x


destroy object

hi, i´m begginer, i have a question:

this is my script, the shield not destroyed after 5 seconds, why?

var shieldforce : GameObject;

function Update() {
    if(Input.GetKeyUp("e"))
        Instantiate(shieldforce, transform.position, transform.rotation);
Destroy(shieldforce, 5);
}
more ▼

asked Jun 30 '12 at 09:24 PM

imrod gravatar image

imrod
0 1 2

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

2 answers: sort voted first

You are nearly there but you are deleting the prefab not the thing you created!

var shieldforce : GameObject;

    function Update() {
        if(Input.GetKeyUp("e")) {
            var newShield : GameObject = Instantiate(shieldforce, transform.position, transform.rotation);
            Destroy(newShield, 5);

     }

    }
more ▼

answered Jun 30 '12 at 09:28 PM

whydoidoit gravatar image

whydoidoit
32.9k 11 23 98

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

Thank you !!!

more ▼

answered Jun 30 '12 at 09:53 PM

imrod gravatar image

imrod
0 1 2

No problem, please tick my answer above and just a note: please use the add new comment button hidden on the right of the screen when commenting rather than posting an answer. UA isn't a forum (which can be confusing at first!)

Jun 30 '12 at 09:55 PM whydoidoit
(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:

x764
x321

asked: Jun 30 '12 at 09:24 PM

Seen: 252 times

Last Updated: Jun 30 '12 at 09:55 PM