Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Countdown timer for reward system

Discussion in 'Scripting' started by FalconJ, Jun 10, 2015.

Thread Status:
Not open for further replies.
  1. FalconJ

    FalconJ

    Joined:
    Mar 12, 2015
    Posts:
    146
    Hi, does anybody know on how to create a countdown timer in which it will grant a reward for the player when the timer runs out.
    For example, at first the timer will be 5 mins, after acquire the reward, the timer will become 10 mins, next 1 hour, and until 24 hour. When it hit 24 hours, the next timer will also locked at 24 hours.

    Any solutions on this?

    Thank you very much
     
  2. Jarbi-James

    Jarbi-James

    Joined:
    Jun 15, 2013
    Posts:
    54
    Hi mate,

    Have a look at this tutorial to get a timer system working:


    To use multiple times you could set the timeRemaining value to the highest time you want to use and then set conditions at each of the intervals where you want something to happen.

    Something like...

    Code (csharp):
    1. If (timeRemaining < 10)
    2. //...doSomething();
    3.  
    4. if (timeRemaining < 5)
    5. // ...dosomethingElse();
    6.  
     
  3. FalconJ

    FalconJ

    Joined:
    Mar 12, 2015
    Posts:
    146
    Hi james,

    I finally used dateTimeutil.currentunix for the time, but since it only displayed in seconds, is it possible to display it in this format --> hours : minutes : seconds

    thank you
     
  4. rangesstudio

    rangesstudio

    Joined:
    Nov 23, 2021
    Posts:
    6
    suppose to late to help you now, but for anyone who finds this:


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

    public class RewardScript : MonoBehaviour
    {
    private void Awake()
    {
    Debug.Log(System.DateTime.Now.TimeOfDay.Minutes);

    Debug.Log(System.DateTime.Now.TimeOfDay + new TimeSpan(0,10,0));
    }
    }
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    Please don't necro posts. Closing.
     
    Kurt-Dekker likes this.
Thread Status:
Not open for further replies.