using System.Collections; using UnityEngine; namespace SpellBoundAR.MusicalInstruments.Piano { public class PhysicalPianoKey : PianoKey { [SerializeField] private Quaternion localRotationWhenUp; [SerializeField] private Quaternion localRotationWhenDown; protected override void GoDown() { StartCoroutine(GoDownAnimation()); } private IEnumerator GoDownAnimation() { for (float timer = 0f; timer < animationSecondsUp; timer += Time.unscaledDeltaTime) { float progress = timer / animationSecondsUp; transform.localRotation = Quaternion.Lerp(localRotationWhenUp, localRotationWhenDown, progress); yield return null; } transform.localRotation = localRotationWhenDown; } protected override void GoUp() { StartCoroutine(GoUpAnimation()); } private IEnumerator GoUpAnimation() { for (float timer = 0f; timer < animationSecondsUp; timer += Time.unscaledDeltaTime) { float progress = timer / animationSecondsUp; transform.localRotation = Quaternion.Lerp(localRotationWhenDown, localRotationWhenUp, progress); yield return null; } transform.localRotation = localRotationWhenUp; } } }