SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using UnityEngine;
  3. public class Clock : UnityEngine.MonoBehaviour
  4. {
  5.     public Transform hoursTransform;
  6.     public Transform minutesTransform;
  7.     public Transform secondsTransform;
  8.     public bool continuous;
  9.     private void Update()
  10.     {
  11.         if (continuous)
  12.             UpdateContinuous();
  13.         else
  14.             UpdateDiscrete();
  15.     }
  16.     void UpdateDiscrete()
  17.     {
  18.         DateTime time = DateTime.Now;
  19.         Debug.Log("System.DateTime.Now.Hour: " + DateTime.Now.Hour);
  20.         Quaternion.Euler(0, DateTime.Now.Hour, 0);
  21.         Quaternion.Euler(0f, DateTime.Now.Hour * 30f, 0f);
  22.         const float degreesPerHour = 30f;
  23.         hoursTransform.localRotation =
  24.             Quaternion.Euler(0f, DateTime.Now.Hour * degreesPerHour, 0f);
  25.         Debug.Log("System.DateTime.Now.Minute: " + DateTime.Now.Minute);
  26.         Quaternion.Euler(0, DateTime.Now.Minute, 0);
  27.         Quaternion.Euler(0f, DateTime.Now.Minute * 6f, 0f);
  28.         const float degreesPerMinute = 6f;
  29.         minutesTransform.localRotation =
  30.             Quaternion.Euler(0f, DateTime.Now.Minute * degreesPerMinute, 0f);
  31.         Debug.Log("System.DateTime.Now.Second: " + DateTime.Now.Second);
  32.         Quaternion.Euler(0, DateTime.Now.Second, 0);
  33.         Quaternion.Euler(0f, DateTime.Now.Second * 6f, 0f);
  34.         const float degreesPerSecond = 1f;
  35.         secondsTransform.localRotation =
  36.             Quaternion.Euler(0f, DateTime.Now.Second * degreesPerSecond, 0f);
  37.     }
  38.     void UpdateContinuous()
  39.     {
  40.         TimeSpan time = DateTime.Now.TimeOfDay;
  41.         hoursTransform.localRotation =
  42.             Quaternion.Euler(0f, (float)time.TotalHours * DegreesPerHour, 0f);
  43.         DateTime time1 = DateTime.Now;
  44.         Debug.Log("System.DateTime.Now.Hour: " + DateTime.Now.Hour);
  45.         Quaternion.Euler(0, DateTime.Now.Hour, 0);
  46.         Quaternion.Euler(0f, DateTime.Now.Hour * 30f, 0f);
  47.         const float degreesPerHour = 30f;
  48.         hoursTransform.localRotation =
  49.             Quaternion.Euler(0f, DateTime.Now.Hour * degreesPerHour, 0f);
  50.         TimeSpan time2 = DateTime.Now.TimeOfDay;
  51.         minutesTransform.localRotation =
  52.             Quaternion.Euler(0f, (float)time.TotalMinutes * DegreesPerMinute, 0f);
  53.         Debug.Log("System.DateTime.Now.Minute: " + DateTime.Now.Minute);
  54.         Quaternion.Euler(0, DateTime.Now.Minute, 0);
  55.         Quaternion.Euler(0f, DateTime.Now.Minute * 6f, 0f);
  56.         const float degreesPerMinute = 6f;
  57.         minutesTransform.localRotation =
  58.             Quaternion.Euler(0f, DateTime.Now.Minute * degreesPerMinute, 0f);
  59.         TimeSpan time3 = DateTime.Now.TimeOfDay;
  60.         secondsTransform.localRotation =
  61.             Quaternion.Euler(0f, (float)time.TotalSeconds * DegreesPerSecond, 0f);
  62.         Debug.Log("System.DateTime.Now.Second: " + DateTime.Now.Second);
  63.         Quaternion.Euler(0, DateTime.Now.Second, 0);
  64.         Quaternion.Euler(0f, DateTime.Now.Second * 6f, 0f);
  65.         const float degreesPerSecond = 1f;
  66.         secondsTransform.localRotation =
  67.             Quaternion.Euler(0f, DateTime.Now.Second * degreesPerSecond, 0f);
  68.     }
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top