Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CharacterStateMachine : StateMachine<Character, CharacterState>
- {
- public CharacterStateMachine(Character context) : base(context) { }
- public CharacterState IdlingState { get; private set; }
- public CharacterState WalkingState { get; private set; }
- public CharacterState RunningState { get; private set; }
- public CharacterState JumpingState { get; private set; }
- public CharacterState FallingState { get; private set; }
- public override void Awake()
- {
- base.Awake();
- IdlingState = new IdlingCharacterState(Context);
- WalkingState = new WalkingCharacterState(Context);
- RunningState = new RunningCharacterState(Context);
- JumpingState = new JumpingCharacterState(Context);
- FallingState = new FallingCharacterState(Context);
- }
- public override void Start()
- {
- base.Start();
- SwitchState(IdlingState);
- }
- public override void FixedUpdate()
- {
- base.FixedUpdate();
- if (Context.IsGrounded())
- {
- if (Context.JumpCallbackContext > 0f)
- {
- SwitchState(JumpingState);
- }
- else
- {
- SwitchState(IdlingState);
- }
- }
- else
- {
- SwitchState(FallingState);
- }
- if (Context.WalkCallbackContext.magnitude != 0f)
- {
- if (Context.RunCallbackContext > 0f)
- {
- SwitchState(RunningState);
- }
- else
- {
- SwitchState(WalkingState);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment