PlayerStateFactory

Contains all the available Player States.

How can I add a new State?

First, make a new script that inherits from PlayerBaseState. Take a look at the provided example code:

using UnityEngine;
namespace cowsins
{
    public class PlayerCustomState : PlayerBaseState
    {

        public PlayerCustomState (PlayerStates currentContext, PlayerStateFactory playerStateFactory)
            : base(currentContext, playerStateFactory) { }

        public override void EnterState()
        {
            // Do something on entering the state
        }

        public override void UpdateState()
        {
            CheckSwitchState();
        }

        public override void FixedUpdateState() { }

        public override void ExitState() {
            // Do something on exiting the state
        }

        public override void CheckSwitchState() { }

        public override void InitializeSubState() { }

    }
}

Once you have this, we need to register this state in the PlayerStateFactory.cs as shown:

public PlayerBaseState Die() { return new PlayerCustomState(_context, this); }

List of Available PlayerStates

  1. PlayerDefaultState

  2. PlayerJumpState

  3. PlayerDeadState

  4. PlayerDashState

  5. PlayerCrouchState

  6. PlayerClimbState

Last updated