- Home /
destrory prefab
destroy the old prefab instantiated when new one is instantiated destroy old prefab with out destroying newly created prefab.
You should not destroy the prefab.. Destroy the gameObject which you have instantiated from that prefab
Answer by X-devGames · Jun 06, 2013 at 09:02 AM
The code below is what i use to destroy a soldier when his health is 0 and replace him with a ragdoll just put your old GameObject you want to destroy in the dead variable and the GameObject you want to replace it with in the deadNew variable. I hope this helps
var MaxHealth : int = 100; var CurrentHealth : int; var dead : Transform; var deadNew: Transform; function Start () { CurrentHealth = MaxHealth; } function ApplyDamage ( Damage : float ) { if(CurrentHealth < 0){ return; } CurrentHealth -= Damage; if(CurrentHealth == 0){ dead = Instantiate(deadNewPos, dead.transform.position, dead.transform.rotation); Destroy(gameObject); } }
Your answer