Advertisement
MrSterling

Clock.cs

Feb 20th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Clock : MonoBehaviour {
  7.  
  8.     public Transform hourTransform, minuteTransform, secondTransform;
  9.  
  10.     public bool sweeping;
  11.  
  12.     void Update () {
  13.         if (sweeping) {
  14.             UpdateSweeping ();
  15.         }
  16.         else {
  17.             UpdateTicking ();
  18.         }
  19.     }
  20.  
  21.     void UpdateSweeping () {
  22.         hourTransform.localRotation =
  23.             Quaternion.Euler(0, (float)DateTime.Now.TimeOfDay.TotalHours * 30, 0);
  24.         minuteTransform.localRotation =
  25.             Quaternion.Euler(0, (float)DateTime.Now.TimeOfDay.TotalMinutes * 6, 0);
  26.         secondTransform.localRotation =
  27.             Quaternion.Euler(0, DateTime.Now.Second * 6, 0);
  28.     }
  29.  
  30.     void UpdateTicking () {
  31.         hourTransform.localRotation =
  32.             Quaternion.Euler(0, DateTime.Now.Hour * 30, 0);
  33.         minuteTransform.localRotation =
  34.             Quaternion.Euler(0, DateTime.Now.Minute * 6, 0);
  35.         secondTransform.localRotation =
  36.             Quaternion.Euler(0, DateTime.Now.Second * 6, 0);
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement