标签:unity3d
using UnityEngine; using System.Collections; using System; public class ClockAnimator : MonoBehaviour { public GameObject hourNeedle; public GameObject minuteNeedle; public GameObject secondNeedle; private const float hourToDegrees = 360f / 12f; private const float minuteToDegrees = 360f / 60f; private const float secondToDegrees = 360f / 60f; public bool analog; // Update is called once per frame void Update () { if (analog) { TimeSpan timespan = DateTime.Now.TimeOfDay; hourNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalHours * -hourToDegrees); minuteNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalMinutes * -minuteToDegrees); secondNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, (float)timespan.TotalSeconds * -secondToDegrees); } else { DateTime time = DateTime.Now; hourNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, time.Hour * -hourToDegrees); minuteNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, time.Minute * -minuteToDegrees); secondNeedle.transform.localRotation = Quaternion.Euler(0f, 0f, time.Second * -secondToDegrees); } } }
https://github.com/U-Xia/Clock
标签:unity3d
原文地址:http://blog.csdn.net/bigpaolee/article/details/40384283