- Home /
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);
}
Comment
Answer by whydoidoit · Jun 30, 2012 at 09:28 PM
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);
}
}
Answer by imrod · Jun 30, 2012 at 09:53 PM
Thank you !!!
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!)