Tutorials

How to create an analog clock in Unity

Tutorial

Intro.

Maybe you want to add a real clock in your Unity game and you don't have any clue how to do it. In this small tutorial I will show you how I did it and you could put it in your project.

Context

We are going to use the DateTime.Now property. This property value is the current local date and time. More information here: DateTime.Now.

We should calculate how many degree each hand needs to move in order to represent the time. Since we know that the whole trajectory will be 360 degrees, the calculations will be:

  • Degrees per second for seconds hand: 360 degrees / 60 seconds
  • Degrees per second for minute hand: 360 degrees / 360 seconds (in 1 hour we have 60 minutes and each minute has 60 seconds).
  • Degrees per second for minute hand: 360 degrees / 4320 seconds (in 12 hour we have 720 minutes and each minute has 60 seconds).

Clock GameObject

Code

Final result

This is the final result of my clock working.

Back to projects To main page
Contact

I'd Love To Hear From You.

You can contact me by Twitter, LinkedIn or email.