Script an analog real time wall clock with C#. Rotate and animate the hands using the awesome iTween tool.


❤️ Subscribe to Oxmond Tutorials:
https://bit.ly/SubscribeOxmondTutorials

✅ Download free Analog Wall Clock assets here:
https://www.freepik.com/free-vector/designer-wall-clock-in-a-metal-casing_1310847.htm
Designed by Iconicbestiary

✅ Download the free iTween tool here:
https://assetstore.unity.com/packages/tools/animation/itween-84?aid=1100l4p9k

✅ Other free Asset Packages at the Unity Assets Store:
https://assetstore.unity.com/lists/top-free-packages-13201?aid=1100l4p9k

😷👕 Need a face mask / developer T-shirt? Drop by our shop and get a 20% DISCOUNT on your first purchase by using the discount code OXMONDSALE. Click here:
https://shop.oxmond.com/discount/OXMONDSALE


Clock script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Clock : MonoBehaviour {

    public GameObject secondHand;
    public GameObject minuteHand;
    public GameObject hourHand;
    string oldSeconds;

	void Update () {

        string seconds = System.DateTime.UtcNow.ToString("ss");
        

        if (seconds != oldSeconds) {
            UpdateTimer();
        }
        oldSeconds = seconds;
	}

    void UpdateTimer() {

        int secondsInt = int.Parse(System.DateTime.UtcNow.ToString("ss"));
        int minutesInt = int.Parse(System.DateTime.UtcNow.ToString("mm"));
        int hoursInt = int.Parse(System.DateTime.UtcNow.ToLocalTime().ToString("hh"));
        print(hoursInt + " : " + minutesInt +  " : " + secondsInt);

        iTween.RotateTo(secondHand, iTween.Hash("z", secondsInt * 6 * -1, "time", 1, "easetype", "easeOutQuint"));
        iTween.RotateTo(minuteHand, iTween.Hash("z", minutesInt * 6 * -1, "time", 1, "easetype", "easeOutElastic"));
        float hourDistance = (float)(minutesInt) / 60f;
        iTween.RotateTo(hourHand, iTween.Hash("z", (hoursInt + hourDistance) * 360 / 12 * -1, "time", 1, "easetype", "easeOutQuint"));

    }
}