Skip to content

Instantly share code, notes, and snippets.

@TeraokaAkihiro
Last active May 9, 2017 05:01
Show Gist options
  • Save TeraokaAkihiro/904c31e3ca0595660c46af112ecbb693 to your computer and use it in GitHub Desktop.
Save TeraokaAkihiro/904c31e3ca0595660c46af112ecbb693 to your computer and use it in GitHub Desktop.
Unityでアナログ時計を動かしてみる。 ref: http://qiita.com/teraokaakihiro/items/ccaca6872e4515c2bf1c
using System; // DateTimeに必要
using System.Collections;
using UnityEngine;
public class clockController : MonoBehaviour {
public bool sec; // 秒針の有無
public bool secTick; // 秒針を秒ごとに動かすか
public GameObject hour;
public GameObject minute;
public GameObject second;
void Start ()
{
if (!sec)
Destroy(second); // 秒針を消す
}
void Update ()
{
DateTime dt = DateTime.Now;
hour.transform.eulerAngles = new Vector3(0,0,(float)dt.Hour/12*-360 + (float)dt.Minute/60*-30);
minute.transform.eulerAngles = new Vector3(0,0,(float)dt.Minute/60*-360);
if (sec)
{
if (secTick)
second.transform.eulerAngles = new Vector3(0,0,(float)dt.Second/60*-360);
else
second.transform.eulerAngles = new Vector3(0,0,(float)dt.Second/60*-360 + (float)dt.Millisecond/60/1000*-360);
}
}
}
transform.eulerAngles = new Vector3(x,y,z);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment