Hi guys,
I have a cat splatting on the ground and i want it so that the splat animation plays and then the object is destroyed. How do you make sure an animation plays to the end before you perform an action? At the moment the object is destroyed before the animation gets played. I’m using spritemanager2 btw.
Thanks.
You might use animation events. This allow you to call a function based on an animation frame.
http://docs.unity3d.com/Documentation/Components/animeditor-AnimationEvents.html
If you want a animation to play just before the object is destroyed then you need it to hold for a sec or the length of the animation.
here is what i use now basically the bad guy bob has a health system on him and it decreases every time i shoot him. Once the life reaches 0 he will destroy him self and replace him self with a rigid body. But before the body destroys it plays a animation and then the destroy function is called as well as the apply rigidboady. Here is the script
var MaxHealth : int = 100;
var dead: Transform;
var deadNew: Transform;
var CurrentHeath : int;
function Start () {
CurrentHeath = MaxHealth;
}
function ApplyDamage ( Damage : float ) {
if( CurrentHeath < 0){
return;
}
CurrentHeath -= Damage;
if( CurrentHeath <= 0 ){
GameObject.Find("Soldier2").animation.Play("CrouchRun");
Destroytimer ();
}
}
function Destroytimer (){
yield WaitForSeconds (animation["CrouchRun"].length);
Destroy(gameObject) ;
dead = Instantiate( deadNew, dead.position, dead.transform.rotation);
}
hope this helps
//This is just a concept not a working script!!!
destroy = false
animation.playAutomatically = true;
function Update(){
if animation.isPlaying {
}
else {
destroy = true;
}
}
You Could make a function LateUpdate too, could you not?