johnnygoodguy2000

PlayerIdleState

Oct 23rd, 2025 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | Gaming | 0 0
  1. using System;
  2. using UnityEngine;
  3.  
  4. public class PlayerMoveState : PlayerState
  5. {
  6.     public PlayerMoveState(Player player) : base(player) { }
  7.  
  8.     public override void Enter()
  9.     {
  10.         base.Enter();
  11.        
  12.  
  13.     }
  14.  
  15.     public override void Update()
  16.     {
  17.  
  18.         base.Update();
  19.         if(AttackPressed && combat.CanAttack)
  20.        
  21.             player.ChangeState(player.attackState);
  22.        
  23.        
  24.         else if (JumpPressed)
  25.         {
  26.  
  27.             player.ChangeState(player.jumpState);
  28.         }
  29.         else if (Mathf.Abs(MoveInput.x) < 0.1f)
  30.         {
  31.             player.ChangeState(player.idleState);
  32.         }
  33.         else if (player.isGrounded && RunPressed && MoveInput.y < -0.1f)
  34.         {
  35.             player.ChangeState(player.slideState);
  36.         }
  37.         else
  38.                 {
  39.                     anim.SetBool("isWalking", !RunPressed);
  40.                     anim.SetBool("isRunning", RunPressed);
  41.                 }
  42.     }
  43.  
  44.     public override void FixedUpdate()
  45.     {
  46.         base.FixedUpdate();
  47.         float speed = RunPressed ? player.runSpeed : player.walkSpeed;
  48.         rb.linearVelocity = new Vector2(speed * player.faceDirection, rb.linearVelocity.y);
  49.     }
  50.  
  51.     public override void Exit()
  52.     {
  53.         base.Exit();
  54.         anim.SetBool("isWalking", false);
  55.         anim.SetBool("isRunning", false);
  56.     }
  57.    
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment