using System.Collections; using System.Collections.Generic; using UnityEngine; using InfallibleCode; public class LockWheelRotation : MonoBehaviour { [SerializeField] private Lock _lock; public Animator wheelAnimator; public float rotationIncrease = 30f; public float rotationDuration = 1.0f; // The duration of the rotation public float previousRot; // The previous rotation value public float rotation; // The target rotation value private void Start() { if (wheelAnimator == null) { wheelAnimator = GetComponent(); } rotation = transform.localEulerAngles.z; // Set the target rotation to the current X rotation of the object } public void RotateWheel(bool isIncreasing) { previousRot = rotation; // Set the previous rotation to the current target rotation if (isIncreasing) { rotation += rotationIncrease; // Increase the target rotation by 35 degrees } else { rotation -= rotationIncrease; // Decrease the target rotation by 35 degrees } //transform.localEulerAngles = new Vector3(rotation, 0, 90); StartCoroutine(RotateSmoothly()); // Start the coroutine to smoothly rotate the object } IEnumerator RotateSmoothly() { //float rotationDuration = 1.0f; float rotTime = 0; while (rotTime < 1.0f) // Loop until the rotation is complete (rotTime reaches 1.0) { rotTime += Time.deltaTime / rotationDuration; // Increment rotTime based on the elapsed time and rotation duration float ZRot = Mathf.Lerp(previousRot, rotation, rotTime); // Interpolate the rotation value using Mathf.Lerp transform.localEulerAngles = new Vector3(0, -90, ZRot); // Set the new rotation value for the object yield return null; // Wait for the next frame } _lock.canScrollWheel = true; yield return null; } }