unity如何判断动画是否播放完毕

public class Crystal : MonoBehaviour {

    private Animator anim;
	// Use this for initialization
	void Start () {
		    

        //play动画
        anim = gameObject.GetComponent();
        //anim.SetInteger("MyPlay", 1);
        
    
	}
	
	// Update is called once per frame
	void Update () {
        transform.Rotate(0, 0, 0.2f);


        AnimatorStateInfo animatorInfo;
        animatorInfo = anim.GetCurrentAnimatorStateInfo (0);//必须放在update里
        if ((animatorInfo.normalizedTime > 1.0f) && (animatorInfo.IsName("MyPlay")))//normalizedTime: 范围0 -- 1,  0是动作开始,1是动作结束
        {
            anim.SetInteger("MyPlay", 0);//播放完成后回到待机动画
        }
        

	}
}

 

你可能感兴趣的:(unity3d)