Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using Extras;
  2. using UnityEngine;
  3.  
  4. namespace Core
  5. {
  6.     [RequireComponent(typeof(Animator))]
  7.     public class Character : PhysicsObject
  8.     {
  9.         private Vector3 _initialScale;
  10.         private readonly int _animMoving = Animator.StringToHash("Moving");
  11.        
  12.         private Animator Animator { get; set; }
  13.         private bool Moving { get; set; }
  14.  
  15.         public CharacterType characterType = CharacterType.AI;
  16.  
  17.         public override void Awake()
  18.         {
  19.             base.Awake();
  20.            
  21.             _initialScale = gameObject.transform.localScale;
  22.             Animator = GetComponent<Animator>();
  23.         }
  24.  
  25.         public override void Update()
  26.         {
  27.             base.Update();
  28.            
  29.             Moving = Grounded && Mathf.Abs(Velocity.x) > 0.01f;
  30.             SetAnimParam(_animMoving, Moving);
  31.         }
  32.  
  33.         public void FaceLeft()
  34.         {
  35.             transform.localScale = new Vector3(_initialScale.x * -1, _initialScale.y, 1);
  36.         }
  37.        
  38.         public void FaceRight()
  39.         {
  40.             transform.localScale = new Vector3(_initialScale.x, _initialScale.y, 1);
  41.         }
  42.  
  43.         private void SetAnimParam(int p, bool value)
  44.         {
  45.             Animator.SetBool(p, value);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement