1. public class Crystal : MonoBehaviour {
    2.  
    3. private Animator anim;
    4.  
      // Use this for initialization
    5.  
      void Start () {
    6.  
       
    7. //play动画
    8.  
      anim = gameObject.GetComponent<Animator>();
    9.  
      //anim.SetInteger("MyPlay", 1);
    10.  
    11. }
    12.  
    13. // Update is called once per frame
    14.  
      void Update () {
    15.  
      transform.Rotate(0, 0, 0.2f);
    16.  
    17.  
    18.  
      AnimatorStateInfo  animatorInfo = anim.GetCurrentAnimatorStateInfo (0);//必须放在update里
    19.  
      if ((animatorInfo.normalizedTime > 1.0f) && (animatorInfo.IsName("MyPlay")))//normalizedTime: 范围0 -- 1, 0是动作开始,1是动作结束
    20.  
      {
    21.  
      anim.SetInteger("MyPlay", 0);//播放完成后回到待机动画
    22.  
      }
    23.  
    24. }
    25.  
      }