Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerGroundedState : PlayerBaseState
- {
- public PlayerGroundedState(PlayerStateMachine currentContext,
- PlayerStateFactory playerStateFactory)
- : base(currentContext, playerStateFactory) {
- IsRootState = true;
- }
- public void HandleGravity() {
- Ctx.VerticalVelocity = -9.5f;
- }
- public override void EnterState() {
- //gravity
- InitializeSubState();
- HandleGravity();
- }
- public override void UpdateState() {
- CheckSwitchStates();
- }
- public override void ExitState() {
- }
- public override void CheckSwitchStates()
- {
- //if player is grounded aloow jump
- if (Ctx.InputJump)
- {
- SwitchState(Factory.Jump());
- }
- //if player is grounede allow gravity
- else if (!Ctx.PlayerController.isGrounded)
- {
- SwitchState(Factory.Fall());
- }
- }
- public override void InitializeSubState() {
- if (Ctx.InputMoveX == 0 && Ctx.InputMoveY == 0 && !Ctx.InputRun)
- {
- SetSubState(Factory.Idle());
- }
- else if (Ctx.InputMoveX != 0 && Ctx.InputMoveY != 0 && !Ctx.InputRun)
- {
- SetSubState(Factory.Walk());
- }
- else {
- SetSubState(Factory.Run());
- }
- }
- }
Add Comment
Please, Sign In to add comment