Last active
May 9, 2017 05:01
-
-
Save TeraokaAkihiro/904c31e3ca0595660c46af112ecbb693 to your computer and use it in GitHub Desktop.
Unityでアナログ時計を動かしてみる。 ref: http://qiita.com/teraokaakihiro/items/ccaca6872e4515c2bf1c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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