- Home /
How to check when an animation has FINISHED
can someone help. I have an animation called "StandToRun" and i want the "Run" Animation to play right after the "StandToRun" animation so the transition from standing to run looks smooth. Here is my script
using UnityEngine;
using System.Collections;
public class Animation : MonoBehaviour {
// Use this for initialization
void Start ()
{
animation.Play("Standing");
animation["StandToRun"].speed = 0.8f;
animation["RunToStand"].speed = 0.8f;
}
// Update is called once per frame
void Update ()
{
if(Input.GetKeyDown(KeyCode.W))
{
animation.Play("StandToRun");
}
if(Input.GetKeyUp(KeyCode.W))
{
animation.Play("Standing");
}
}
}
take a look on these methods:
animation.CrossFadeQueued
animation.PlayQueued
not sure if it'll solve it, but should do.
Answer by zharik86 · Mar 12, 2014 at 07:15 PM
In your case you should use CrossFade function:
void Start() {
animation["StandToRun"].speed = 0.8f;
animation["RunToStand"].speed = 0.8f;
animation.CrossFade("Standing");
}
void Update() {
if(Input.GetKeyDown(KeyCode.W)) {
animation.CrossFade("StandToRun");
}
if(Input.GetKeyUp(KeyCode.W)) {
animation.CrossFade("Standing");
}
}
And your animation should be as "Loop", when import. P.S. Check animation playing:
bool animplay = animation.IsPlaying("Standing");
Value true - is playing, value false - not playing.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making an animation on Input run at a speed declared by a variable in another script? 0 Answers
animation.Play (MissingComponentException: There is no 'Animation' attached to.. 2 Answers
Character fall animation 1 Answer
Sliding door animation question. 3 Answers