Advertisement
natmaxex

PlayerIdleState

Aug 11th, 2022 (edited)
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerIdleState : PlayerBaseState
  6. {
  7.     public PlayerIdleState(PlayerStateMachine currentContext,
  8.         PlayerStateFactory playerStateFactory)
  9.     : base(currentContext, playerStateFactory) { }
  10.  
  11.     public override void EnterState() {
  12.         Ctx.PlayerMovementX = 0;
  13.         Ctx.PlayerMovementZ = 0;
  14.  
  15.         //animation
  16.         Ctx.AnimCon.SetFloat(Ctx.HorizontalAnim, 0);
  17.         Ctx.AnimCon.SetFloat(Ctx.VerticalAnim, 0);
  18.     }
  19.  
  20.     public override void UpdateState() {
  21.         CheckSwitchStates();
  22.     }
  23.  
  24.     public override void ExitState() { }
  25.  
  26.     public override void InitializeSubState() { }
  27.  
  28.     public override void CheckSwitchStates() {
  29.         if (Ctx.InputMoveX != 0 || Ctx.InputMoveY != 0) {
  30.             if (Ctx.InputRun)
  31.             {
  32.                 SwitchState(Factory.Run());
  33.             }
  34.             else {
  35.                 SwitchState(Factory.Walk());
  36.             }
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement