Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3.  
  4. public class ClockAnimation : MonoBehaviour {
  5.  
  6.     private const float
  7.     hoursToDegrees = 360f / 12f,
  8.     minutesToDegrees = 360f / 60f,
  9.     secondsToDegrees = 360f / 60f;
  10.  
  11.     public Transform hours, minutes, seconds;
  12.     public bool analog;
  13.  
  14.     private void Update () {
  15.         if (analog) {
  16.             TimeSpan timespan = DateTime.Now.TimeOfDay;
  17.             hours.localRotation = Quaternion.Euler(
  18.                 0f, 0f, (float)timespan.TotalHours * -hoursToDegrees);
  19.             minutes.localRotation = Quaternion.Euler(
  20.                 0f, 0f, (float)timespan.TotalMinutes * -minutesToDegrees);
  21.             seconds.localRotation = Quaternion.Euler(
  22.                 0f, 0f, (float)timespan.TotalSeconds * -secondsToDegrees);
  23.         }
  24.         else {
  25.             DateTime time = DateTime.Now;
  26.             hours.localRotation =
  27.                 Quaternion.Euler(0f, 0f, time.Hour * -hoursToDegrees);
  28.             minutes.localRotation =
  29.                 Quaternion.Euler(0f, 0f, time.Minute * -minutesToDegrees);
  30.             seconds.localRotation =
  31.                 Quaternion.Euler(0f, 0f, time.Second * -secondsToDegrees);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement