- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
abhishakverma · Mar 05, 2014 at 02:24 PM ·
c#javascriptjavascripting
How I can find the complete event of my animation
I am creating a demo in which I play two animation one is default which always run in background and one is when I clicked on my button. I want my default animation stops until my clicked animation not completed and when my clicked animation is complete i will play my default animation again.
using UnityEngine;
using System.Collections;
public class hump_movement : MonoBehaviour {
// Use this for initialization
public GUITexture humpbutton;
public AnimationClip humpanim;
public AnimationClip idle;
public bool myvar= false;
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0) && humpbutton.HitTest (Input.mousePosition)) {
animation.Play(humpanim.name);
Debug.Log("1");
}
else if(!Input.GetMouseButton (0) && humpbutton.HitTest (Input.mousePosition)){
animation.Play (idle.name);
Debug.Log("2");
}
}
}
Comment
Best Answer
Answer by bAStek · Mar 06, 2014 at 12:51 PM
Try to use coroutines. Or look at this THREAD HERE
void Update ()
{
if (Input.GetMouseButton (0) && humpbutton.HitTest (Input.mousePosition))
{
StartCoroutine(PlayAnimation(humpanim.name));
}
}
IEnumerator PlayAnimation(string animationName)
{
animation.CrossFade(animationName, 0.3f);
yield return new WaitForSeconds(animation.GetClip(animationName).length); // wait untill animation ends
animation.Play(idle.name);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613135428im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to implement a low pass filter for accelerometer? 2 Answers
Multiple Cars not working 1 Answer
change .color on contact 1 Answer
Movement script, moving up when moving positively in z axis 1 Answer
snap object to object in game view ? 1 Answer