Dieton

PlayerWalkState

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