Skip to main content
2 of 2
Cleanup
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

How to make a countdown timer based on local time

I have a problem. In my GetTime.cs script, I am getting local time from an Android/iOS device, and simply assigning it to a Text component.

private void Update()
{
    time = System.DateTime.Now.ToLocalTime().ToString("HH:mm:ss");
    timeText.text = time;      
}

I am making a travel system, that takes X amount of seconds to get from point A to point B. While in travel, you cannot do any actions.

How can I make this into a countdown timer based on local time? For example, I want to do travel from point A to point B like this:

  • I am in point A

  • I choose an option to travel to point B

  • I wait 30 seconds

  • I am at point B

But it has to be based on local time, and it has to work in the background, even when the app is not running.