using UnityEngine; /// /// Turns the hour, minute and second hands to the player's own local time (the device clock). /// Hands rotate about this object's local Z axis; 12 o'clock is local +Y. /// public class WallClock : MonoBehaviour { public Transform hourHand, minuteHand, secondHand; [Tooltip("Sweep the second hand smoothly instead of ticking.")] public bool smoothSeconds = false; void Update() { var now = System.DateTime.Now; float sec = now.Second + (smoothSeconds ? now.Millisecond / 1000f : 0f); float min = now.Minute + sec / 60f; float hour = (now.Hour % 12) + min / 60f; Set(hourHand, hour / 12f); Set(minuteHand, min / 60f); Set(secondHand, sec / 60f); } // Clockwise as seen from the front: negative Z rotation, with the face looking toward local -Z static void Set(Transform hand, float turn) { if (hand != null) hand.localRotation = Quaternion.Euler(0f, 0f, -turn * 360f); } }