首页 > 代码库 > 简易时钟
简易时钟
内容来源于开发者社区。
用到的代码如下:
using UnityEngine; using System.Collections; using System; public class ClockAnimator : MonoBehaviour { private const float hoursToDegrees = 360f / 12f, minutesToDegrees = 360f / 60f, secondsToDegrees = 360f / 60f; public Transform hours, minutes, seconds; public bool analog = false; // Use this for initialization void Start() { } // Update is called once per frame void Update() { if (analog) { TimeSpan timeSpan = DateTime.Now.TimeOfDay; hours.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalHours * -hoursToDegrees); minutes.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalMinutes * -minutesToDegrees); seconds.localRotation = Quaternion.Euler(0f, 0f, (float)timeSpan.TotalSeconds * -secondsToDegrees); Debug.Log(secondsToDegrees.ToString()); } else { DateTime time = DateTime.Now; hours.localRotation = Quaternion.Euler(0f, 0f, time.Hour * -hoursToDegrees); minutes.localRotation = Quaternion.Euler(0f, 0f, time.Minute * -minutesToDegrees); seconds.localRotation = Quaternion.Euler(0f, 0f, time.Second * -secondsToDegrees); Debug.Log(time.Second * -secondsToDegrees); } } }
//为了获得和场景视图相机相似的视角,选择相机,然后从菜单中选择GameObject / Align View to Selected。
//为了使指针旋转起来,我们需要改变他们的局部旋转。直接设置指针的localRotation就可以,这要使用四元数。四元数可以定义任意的旋转。 Quaternion.Euler
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。