Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using Extras;
  2. using UnityEngine;
  3.  
  4. namespace Core
  5. {
  6.     [RequireComponent(typeof(CharacterMovement))]
  7.     public class CharacterRun : CharacterComponent
  8.     {
  9.         private static readonly int RunningParam = Animator.StringToHash("Running");
  10.  
  11.         private CharacterMovement _characterMovement;
  12.        
  13.         [SerializeField] private float runSpeed = 5;
  14.  
  15.         public override void Awake()
  16.         {
  17.             base.Awake();
  18.  
  19.             _characterMovement = GetComponent<CharacterMovement>();
  20.         }
  21.        
  22.         private void Update()
  23.         {
  24.             if (Character.characterType != CharacterType.Player)
  25.                 return;
  26.            
  27.             if (Input.GetKeyDown(KeyCode.LeftShift))
  28.                 Run();
  29.             else
  30.                 StopRun();
  31.         }
  32.        
  33.         private void Run()
  34.         {
  35.             _characterMovement.speedMultiplier *= runSpeed;
  36.         }
  37.  
  38.         private void StopRun()
  39.         {
  40.             _characterMovement.speedMultiplier = 1.0f;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement