码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3d 钟表

时间:2014-10-23 00:02:21      阅读:166      评论:0      收藏:0      [点我收藏+]

标签: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 钟表

标签:unity3d

原文地址:http://blog.csdn.net/bigpaolee/article/details/40384283

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!