Advertisement
natmaxex

PlayerFallState

Aug 11th, 2022 (edited)
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerFallState : PlayerBaseState
  6. {
  7.     public PlayerFallState(PlayerStateMachine currentContext,
  8.         PlayerStateFactory playerStateFactory)
  9.     : base(currentContext, playerStateFactory) {
  10.         IsRootState = true;
  11.     }
  12.  
  13.     public override void EnterState() {
  14.         InitializeSubState();
  15.         Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 2);
  16.     }
  17.  
  18.     public override void UpdateState()
  19.     {
  20.         CheckSwitchStates();
  21.  
  22.         if (Ctx.VerticalVelocity < Ctx.TerminalVelocity)
  23.         {
  24.             Ctx.VerticalVelocity += Ctx.Gravity * Time.deltaTime;
  25.         }
  26.     }
  27.  
  28.     public override void ExitState() {
  29.         Ctx.AnimCon.SetInteger(Ctx.JumpAnim, 3);
  30.     }
  31.  
  32.     public override void CheckSwitchStates() {
  33.         if (Ctx.PlayerController.isGrounded) {
  34.             SwitchState(Factory.Grounded());
  35.         }
  36.     }
  37.  
  38.     public override void InitializeSubState() {
  39.         if (Ctx.InputMoveX == 0 && Ctx.InputMoveY == 0 && !Ctx.InputRun)
  40.         {
  41.             SetSubState(Factory.Idle());
  42.         }
  43.         else if (Ctx.InputMoveX != 0 && Ctx.InputMoveY != 0 && !Ctx.InputRun)
  44.         {
  45.             SetSubState(Factory.Walk());
  46.         }
  47.         else
  48.         {
  49.             SetSubState(Factory.Run());
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement