//1.Player代码改变
public PlayerWallJumpState wallJump { get; private set;}
private voidAwake(){
jumpState = new PlayerJumpState(this, stateMachine,"Jump");
airState = new PlayerAirState(this, stateMachine,"Jump");
wallJump = new PlayerWallJumpState(this, stateMachine,"Jump");//三种状态同为Jump动画播放}
//2.新增PlayerWallJump
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerWallJumpState : PlayerState
{
public PlayerWallJumpState(Player _player, PlayerStateMachine _stateMachine, string _animBoolName):base(_player, _stateMachine, _animBoolName){}
public override voidEnter(){
base.Enter();
stateTimer =1f;//状态持续时间
player.SetVelocity(5*-player.facingDir, player.jumpForce);//跳是向反方向跳}
public override voidExit(){
base.Exit();}
public override voidUpdate(){
base.Update();if(stateTimer<0)//小于状态持续时间则恢复为idle状态{
stateMachine.ChangeState(player.idleState);}if(player.IsGroundDetected())//为防止接触地面还处于fall状态动画{
stateMachine.ChangeState(player.idleState);}}}
//3.PlayerWallSlideState代码改变
public override voidUpdate(){
base.Update();if(Input.GetKeyDown(KeyCode.Space)){
stateMachine.ChangeState(player.wallJump);return;//防止进入其他状态}}
//4.PlayerIdleState代码改变(使得转换idle无如何方向速度)
public override voidEnter(){
base.Enter();
rb.velocity = new Vector2(0,0);//使得落地(或其他状态切换为idle带有其他方向速度)}
//5.PlayerDashState代码改变(修复空中dash碰到墙体可以转化为wallslide)
public override voidUpdate(){
base.Update();if(!player.IsGroundDetected()&&player.IsWallDetected())//使得在空中dash也能在碰撞到墙体时进行slide {
stateMachine.ChangeState(player.wallSlide);}}