using UnityEngine; using UnityEngine.InputSystem; public class AnimationSkip : MonoBehaviour { //checks if an animation is playing on the object it is attached to. //stops the animation and then destroys itself. private Animator targetAnim; private void Awake() { targetAnim = GetComponent<Animator>(); } private void Update() { Gamepad currentPad = Gamepad.current; if (currentPad == null) { if (Keyboard.current.wasUpdatedThisFrame || Mouse.current.leftButton.wasPressedThisFrame) { if (!targetAnim.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { targetAnim.Play("Idle", 0, 0); Destroy(this); } } } else { if (Keyboard.current.wasUpdatedThisFrame || Mouse.current.leftButton.wasPressedThisFrame || Gamepad.current.wasUpdatedThisFrame) { if (!targetAnim.GetCurrentAnimatorStateInfo(0).IsName("Idle")) { targetAnim.Play("Idle", 0, 0); Destroy(this); } } } } }