Question by
abc123weee · Mar 27, 2016 at 08:11 PM ·
animationgetcomponentfunctionif-statementsyield waitforseconds
How do I run an animation then destroy a game object?
I'm trying to code a scenario where after a zombie's health is below zero, it runs an animation (name of the animation is "back_fall") then after 2 seconds(ish) is destroyed. This is my current code:
var EnemyHealth : int = 100; var Zombie : GameObject;
function DeductPoints (DamageAmount : int) {
EnemyHealth -= DamageAmount;
}
if( EnemyHealth <= 0 ){ GameObject.Find("Zombie").animation.Play("back_fall"); Destroytimer (); }
function Destroytimer (){ yield WaitForSeconds (animation["back_fall"].length); Destroy(gameObject); }
// I can't get all of my codes in the box, but that's it.
Comment