- Home /
Question by
sarahAiyad · Sep 27, 2013 at 11:32 AM ·
javascriptdestroyclone
error in destroying bullet prefab
hi, i want to destroy bullet prefab when it is instantiated after 2 seconds and i wrote this code, but it doesn't working, and during playing mode the cloned prefabs doesn't destroyed
var seconds : float =2;
static var playerShooting:GameObject ;
function OnCollisionEnter(other : Collision){
if(other.gameObject.name == "Player"){
Destroy(this.gameObject);
}
if(other.gameObject.GetComponent("Health")){
Health.enemy = playerShooting.name;
Health.health -=10 ;
}
}
function start(){
yield new WaitForSeconds(seconds);
Destroy(this.gameObject);
}
Comment
Best Answer
Answer by CHPedersen · Sep 27, 2013 at 11:37 AM
I'm assuming this is the bullet script?
It's not being automatically destroyed because you misspelled the Start callback. It is with a capital "S". Spelling it with a lower case "s" just defines your own private start, which is not called by Unity. Change it to:
function Start(){
yield new WaitForSeconds(seconds);
Destroy(this.gameObject);
}
Your answer
Follow this Question
Related Questions
Destroy Clones One At A Time Javascript 0 Answers
Destroying a gameobject clone after a time 3 Answers
Can someone explain the destroy () command? 1 Answer
How could i optimize this code 2 Answers