Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. [RequireComponent(typeof(Animator))]
  4. public class PulseToBeat : MonoBehaviour
  5. {
  6.     [SerializeField]private RuntimeAnimatorController _defaultController;
  7.     private Animator _animator;
  8.  
  9.     private void Start()
  10.     {
  11.         SongManager.Instance.Beat += PulseToBeat_Beat;
  12.         _animator = GetComponent<Animator>();
  13.     }
  14.  
  15.     private void OnValidate()
  16.     {
  17.         if (GetComponent<Animator>().runtimeAnimatorController == null)
  18.             GetComponent<Animator>().runtimeAnimatorController = _defaultController;
  19.     }
  20.  
  21.     private void OnDestroy()
  22.     {
  23.         SongManager.Instance.Beat -= PulseToBeat_Beat;
  24.     }
  25.    
  26.     private void PulseToBeat_Beat(int obj)
  27.     {
  28.         if (gameObject.activeInHierarchy)
  29.         {
  30.             _animator.SetTrigger("Beat");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement