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