1. // Use this for initialization 
  2. void Start () { 
  3.     this.anim_stand = this.animation[ANI_Stand]; 
  4.     anim_stand.wrapMode = WrapMode.Loop; 
  5.     bindAnimationEvent(anim_stand); 
  6.      
  7.     this.anim_die = this.animation[ANI_Die]; 
  8.     anim_die.wrapMode = WrapMode.Once; 
  9.     bindAnimationEvent(anim_die); 
  10.      
  11.     this.anim_walk = this.animation[ANI_Walk]; 
  12.     anim_walk.wrapMode = WrapMode.Loop; 
  13.      
  14.     //点击之后转入 idle state  
  15.     this.anim_click = this.animation[ANI_Click]; 
  16.     anim_click.wrapMode = WrapMode.Once; 
  17.     bindAnimationEvent(anim_click); 
  18.      
  19.      
  20.     this.anim_attack1 = this.animation[ANI_Attack1]; 
  21.     anim_attack1.wrapMode = WrapMode.Once; 
  22.     bindAnimationEvent(anim_attack1); 
  23.      
  24.     this.anim_attack2 = this.animation[ANI_Attack2]; 
  25.     anim_attack2.wrapMode = WrapMode.Once; 
  26.     bindAnimationEvent(anim_attack2); 
  27.  
  28.     character  = GetComponent<CharacterController>(); 
  29.          
  30.     this.SetState(PlayerState.idle); 
  31.  
  32. void bindAnimationEvent(AnimationState animState) 
  33.     AnimationEvent animEvent = new AnimationEvent(); 
  34.     animEvent.functionName = "toNextStep"
  35.     animEvent.time = animState.length; 
  36.     animState.clip.AddEvent(animEvent);      
  37.  
  38.      
  39. void toNextStep() 
  40.     switch(this.state) 
  41.     { 
  42.     case PlayerState.moving: 
  43.         this.SetState(PlayerState.attacking); 
  44.         break
  45.          
  46.     case PlayerState.attacking: 
  47.         this.SetState(PlayerState.idle); 
  48.         break
  49.          
  50.     case PlayerState.clicked: 
  51.         this.SetState(PlayerState.idle); 
  52.         break
  53.     }