Dieton

PlayerRunState

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