码迷,mamicode.com
首页 > 其他好文 > 详细

简易时钟

时间:2014-05-24 00:47:44      阅读:308      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   c   code   java   

内容来源于开发者社区

用到的代码如下:

bubuko.com,布布扣
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);
        }
    }
}
bubuko.com,布布扣

 

//为了获得和场景视图相机相似的视角,选择相机,然后从菜单中选择GameObject / Align View to Selected。

//为了使指针旋转起来,我们需要改变他们的局部旋转。直接设置指针的localRotation就可以,这要使用四元数。四元数可以定义任意的旋转。 Quaternion.Euler

简易时钟,布布扣,bubuko.com

简易时钟

标签:style   class   blog   c   code   java   

原文地址:http://www.cnblogs.com/hometown/p/3736934.html

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