ClockScrip.cs
using UnityEngine;
using System;
class ClockScript : MonoBehaviour
{
const float hoursIndex = 60f, minutesIndex = 6f, secondsIndex = 6f;
[SerializeField]
Transform hoursArm, minutesArm, secondsArm;
private void FixedUpdate()
{
TimeSpan time = DateTime.Now.TimeOfDay;
hoursArm.localRotation = Quaternion.Euler(0f, (float)time.TotalHours * hoursIndex, 0f);
minutesArm.localRotation = Quaternion.Euler(0f, (float)time.TotalMinutes * minutesIndex, 0f);
secondsArm.localRotation = Quaternion.Euler(0f, (float)time.TotalSeconds * secondsIndex, 0f);
}
}
实现时钟笔记
参考https://catlikecoding.com/unity/tutorials/basics/game-objects-and-scripts/