Unity Analog Clock Tutorial | Unity Tutorial
In this video tutorial, we'll guide you through creating a stunning analog clock in Unity! We'll start with the graphics setup, showing you how to design the clock face and hands using Unity's UI tools. Then, we'll dive into script writing, where you'll learn to implement real-time functionality to keep your clock ticking accurately.
WATCH FULL TUTORIAL ON YOUTUBE
=========================================================
Unity Projects - ON SALE!!!
1. Water Sort Puzzle 9000 Levels
2. Ball Sort Puzzle 9000 Levels
3. Sling Shot
=========================================================
Script:
AnalogClock.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnalogClock : MonoBehaviour
{
public RectTransform hourHand;
public RectTransform minuteHand;
public RectTransform secondHand;
// Update is called once per frame
void Update()
{
System.DateTime time = System.DateTime.Now;
float seconds = time.Second;
float minutes = time.Minute + seconds / 60f;
float hours = time.Hour % 12 + minutes / 60f;
secondHand.localRotation = Quaternion.Euler(0, 0f, -seconds * 6f);
minuteHand.localRotation = Quaternion.Euler(0, 0f, -minutes * 6f);
hourHand.localRotation = Quaternion.Euler(0, 0f, -hours * 30f);
}
}