Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2. using Extras;
  3. using UnityEngine;
  4.  
  5. namespace Core
  6. {
  7.     public class CharacterMovement : CharacterComponent
  8.     {
  9.         public float maxSpeed = 7;
  10.        
  11.         [HideInInspector] public float speedMultiplier = 1;
  12.        
  13.         private void Update()
  14.         {
  15.             if (Character.characterType != CharacterType.Player)
  16.                 return;
  17.            
  18.             var move = Vector2.zero;
  19.             move.x = Input.GetAxis("Horizontal");
  20.  
  21.             if (move.normalized.magnitude > 0.1f)
  22.             {
  23.                 if (move.normalized.x > 0)
  24.                     Character.FaceRight();
  25.                 else
  26.                     Character.FaceLeft();
  27.             }
  28.  
  29.             Character.TargetVelocity = move * (maxSpeed * speedMultiplier);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement