Unity时钟
using UnityEngine;
using UnityEngine.UI;

public class ClockControl : MonoBehaviour
{
    public Transform clock;
    public Slider slider;
    public Vector3 targetRotation;
    public Vector3 currentRotation;

    public float interval = 2;
    public float timer;
    public bool status;

    public void Update()
    {
        if (status)
        {
            timer += Time.deltaTime;
            if (timer < interval)
            {
                // print( $"currentRotation: {currentRotation}, targetRotation: {targetRotation}");
                clock.localEulerAngles = Vector3.Lerp(currentRotation, targetRotation, timer / interval);
                return;
            }

            timer = 0;
            status = false;
        }
    }

    public void SetTargetRotation(float value)
    {
        status = false;
        currentRotation = new Vector3(0, 0, -360) + clock.localEulerAngles;
        targetRotation = new Vector3(0, 0, Mathf.Lerp(0, -360, value));
        // print($"{currentRotation} : {targetRotation}");
        timer = 0;
        status = true;
    }
}
上一篇
下一篇