diff --git a/Assets/_PROJECT/Components/Portals2/Play Animation On Trigger.cs b/Assets/_PROJECT/Components/Portals2/Play Animation On Trigger.cs index d26f528a..1a359c80 100644 --- a/Assets/_PROJECT/Components/Portals2/Play Animation On Trigger.cs +++ b/Assets/_PROJECT/Components/Portals2/Play Animation On Trigger.cs @@ -1,10 +1,22 @@ +using System.Collections.Generic; using UnityEngine; public class PlayAnimationOnTrigger : MonoBehaviour { - [SerializeField] public Animator animator; // Reference to the Animator component - [SerializeField] public string animationName = "YourAnimation"; // Name of the animation to play + public enum KnownAnimations + { + UFOFlight1 + } + protected Dictionary animationNames = new Dictionary(); + + [SerializeField] public Animator animator; // Reference to the Animator component + [SerializeField] public KnownAnimations animationName = KnownAnimations.UFOFlight1; // Name of the animation to play + + protected void Awake() + { + animationNames[KnownAnimations.UFOFlight1] = "UFO group flight 1"; + } private void OnTriggerEnter(Collider other) { @@ -15,15 +27,16 @@ public class PlayAnimationOnTrigger : MonoBehaviour return; } + string animationNameString = animationNames[animationName]; + // Check if the animation is already playing - if (animator.GetCurrentAnimatorStateInfo(0).IsName(animationName) && animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1) + if (animator.GetCurrentAnimatorStateInfo(0).IsName(animationNameString) && animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1) { - Debug.Log("Animation is already playing."); return; } // Play the animation - animator.Play(animationName, 0, 0f); - Debug.Log("Playing animation: " + animationName); + animator.Play(animationNameString, 0, 0f); + Debug.Log("Playing animation: " + animationNameString); } }