- // Use this for initialization
- void Start () {
- this.anim_stand = this.animation[ANI_Stand];
- anim_stand.wrapMode = WrapMode.Loop;
- bindAnimationEvent(anim_stand);
- this.anim_die = this.animation[ANI_Die];
- anim_die.wrapMode = WrapMode.Once;
- bindAnimationEvent(anim_die);
- this.anim_walk = this.animation[ANI_Walk];
- anim_walk.wrapMode = WrapMode.Loop;
- //点击之后转入 idle state
- this.anim_click = this.animation[ANI_Click];
- anim_click.wrapMode = WrapMode.Once;
- bindAnimationEvent(anim_click);
- this.anim_attack1 = this.animation[ANI_Attack1];
- anim_attack1.wrapMode = WrapMode.Once;
- bindAnimationEvent(anim_attack1);
- this.anim_attack2 = this.animation[ANI_Attack2];
- anim_attack2.wrapMode = WrapMode.Once;
- bindAnimationEvent(anim_attack2);
- character = GetComponent<CharacterController>();
- this.SetState(PlayerState.idle);
- }
- void bindAnimationEvent(AnimationState animState)
- {
- AnimationEvent animEvent = new AnimationEvent();
- animEvent.functionName = "toNextStep";
- animEvent.time = animState.length;
- animState.clip.AddEvent(animEvent);
- }
- void toNextStep()
- {
- switch(this.state)
- {
- case PlayerState.moving:
- this.SetState(PlayerState.attacking);
- break;
- case PlayerState.attacking:
- this.SetState(PlayerState.idle);
- break;
- case PlayerState.clicked:
- this.SetState(PlayerState.idle);
- break;
- }
- }