Home khkGames Classes Calendar Software Bibliothek Index Contact
Trail: Clock.cs

Clock.cs

 using UnityEngine;
 public class Clock : MonoBehaviour {
	const float 
		degreesPerHour = 30f,
		degreesPerMinute = 6f,
		degreesPerSecond = 6f;
	public Transform hoursTransform, minutesTransform, secondsTransform;
	public bool continuous;
	//public Transform minutesTransform;
	//public Transform secondsTransform;
	//Debug.Log(System.DateTime.Now.Hour);
		void UpdateContinuous() {
		System.TimeSpan time = System.DateTime.Now.TimeOfDay;
		hoursTransform.localRotation =
			Quaternion.Euler(0f, (float)time.TotalHours * degreesPerHour, 0f);
		minutesTransform.localRotation =
			Quaternion.Euler(0f, (float)time.TotalMinutes * degreesPerMinute, 0f);
		secondsTransform.localRotation =
			Quaternion.Euler(0f, (float)time.TotalSeconds * degreesPerSecond, 0f);
	}
		void UpdateDiscrete() {
		System.DateTime time = System.DateTime.Now;
		hoursTransform.localRotation =
			Quaternion.Euler(0f, time.Hour * degreesPerHour, 0f);
		minutesTransform.localRotation =
			Quaternion.Euler(0f, time.Minute * degreesPerMinute, 0f);
		secondsTransform.localRotation =
			Quaternion.Euler(0f, time.Second * degreesPerSecond, 0f);
	}
		private void Update() {
			if (continuous){
				UpdateContinuous();
			}
			else
			{
				UpdateDiscrete();
			}
		}
 }