Wednesday, February 10, 2016

unity - How can I do something only after an animation has finished?


I'm making this 2D platform based game. Basically what I want is when the player walks into spikes (which have a "deadly" tag") it displays the animation that has the parameter of animate with the value of 3 and after that the player gets destroyed. So my question is:



  • How do I build a timer or something so that the object only gets destroyed after the animation is played (with no looping)?


This is the code I'm using now:


void OnTriggerEnter2D(Collider2D target) {
if (target.gameObject.tag == "Deadly") {
Die();
}

}

void Die() {
animator.SetInteger ("AnimState", 3);
Destroy (gameObject);
}


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...