Advertisement
Pro_Unit

BodyAnimator

Nov 25th, 2020
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(Animator))]
  6. public class BodyAnimator : MonoBehaviour
  7. {
  8.    
  9.     protected Animator animator;
  10.    
  11.     [SerializeField] private BodyAnimationState _state;
  12.  
  13.     public BodyAnimationState state
  14.     {
  15.         get => _state;
  16.         set
  17.         {
  18.             CallAnimation(value);
  19.             _state = value;
  20.         }
  21.     }
  22.     private Dictionary<BodyAnimationState, int> animationMap = new Dictionary<BodyAnimationState, int>
  23.     {
  24.         {BodyAnimationState.Standart, Animator.StringToHash("GoesToStandartTrigger")},
  25.         {BodyAnimationState.PlayerGoesLeft, Animator.StringToHash("GoesLeftTrigger")},
  26.         {BodyAnimationState.PlayerGoesUp, Animator.StringToHash("GoesUpTrigger")}
  27.     };
  28.    
  29.     private void Start() => animator = GetComponent<Animator>();
  30.     private void CallAnimation(BodyAnimationState callState) => animator.SetTrigger(animationMap[callState]);
  31. }
  32.  
  33. public enum BodyAnimationState{Standart, PlayerGoesLeft, PlayerGoesUp}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement