//time 退出状态时间 void SetState(PalyerState state, float time = 0) { this.SetStateAndAnim(state); if (time <= 0) { return; } else { StartCoroutine(ExitStateCor(state, time)); } }
IEnumerator ExitStateCor(PalyerState state, float time) { yield return(new WaitForSeconds(time)); if (state == PalyerState.Jump) { if (Input.GetKey(KeyCode.D)) { this.SetStateAndAnim(PalyerState.Walk); } else { this.SetStateAndAnim(PalyerState.Idle); } } else if (state == PalyerState.Down) { if (Input.GetKey(KeyCode.D)) { this.SetStateAndAnim(PalyerState.DownWalk); } else { this.SetStateAndAnim(PalyerState.DownIdle); } } else if (state == PalyerState.Dress) { if (Input.GetKey(KeyCode.D)) { this.SetStateAndAnim(PalyerState.Walk); } else { this.SetStateAndAnim(PalyerState.Idle); } } }
void SetStateAndAnim(PalyerState state) { this.state = state; //Debug.Log("state:" + state); if (state == PalyerState.Idle) { this.animationCom.Play("idle"); if (this.modelAnimator != null) { this.modelAnimator.Play("idle"); } } else if (state == PalyerState.Walk) { this.animationCom.Play("walk"); if (this.modelAnimator != null) { this.modelAnimator.Play("walk"); } } else if (state == PalyerState.Jump) { this.animationCom.Play("jump"); if (this.modelAnimator != null) { this.modelAnimator.Play("jump"); } } else if (state == PalyerState.Down) { this.animationCom.Play("down"); if (this.modelAnimator != null) { this.modelAnimator.Play("down"); } } else if (state == PalyerState.DownWalk) { this.animationCom.Play("downwalk"); if (this.modelAnimator != null) { this.modelAnimator.Play("downwalk"); } } else if (state == PalyerState.DownIdle) { this.animationCom.Play("downidle"); if (this.modelAnimator != null) { this.modelAnimator.Play("downidle"); } } else if (state == PalyerState.Dress) { //this.animationCom.Play("dress"); if (this.modelAnimator != null) { this.modelAnimator.Play("dress"); } } }