纳金网
标题:
实现一个简单的小表盘时钟
[打印本页]
作者:
王者再临
时间:
2014-11-30 08:24
标题:
实现一个简单的小表盘时钟
public Transform secondHandPivot;
public Transform minuteHandPivot;
public Transform hourHandPivot;
DateTime time = DateTime.Now;
float seconds = (float)time.Second;
float minutes = (float)time.Minute;
float hours12 = (float)time.Hour % 12;
float angleSeconds = -360 * (seconds / 60);
float angleMinutes = -360 * (minutes / 60);
float angleHours = -360 * (hours12 / 12);
secondHandPivot.localRotation=Quaternion.Euler(0f,0f,angleSeconds);
minuteHandPivot.localRotation=Quaternion.Euler(0f,0f,angleMinutes);
hourHandPivot.localRotation=Quaternion.Euler(0f,0f,angleHours);
注意:因为unity使用的是左手坐标系排列Z轴,旋转角度只能是负数,因此负的360乘以时间可以得到旋转的角度。
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5