How to Refill lotto ticket after 24 hours even when the game is closed

Okay my friends told me that I should subtract the time when the ticket ran out to the current time.
but my currentDate.Hour- dateNoTries.Hour and currentDate.Minute - dateNoTries.Minute always returns an hours passed and minutes passed not hours remaining and minutes remaning.

using UnityEngine;
using System.Collections;
using System;

public class liveTimer : MonoBehaviour
{

public DateTime dateNoTries;
public DateTime currentDate;

public bool dataGathered;


void Start()
{

}

void Update()
{
    currentDate = System.DateTime.Now;

    if (dataManager.gameDataManager.lottoTries == 0)
    {
        if (!dataGathered)
        {
            dateNoTries = System.DateTime.Now;

            Debug.Log("Hours out of tries: " + dateNoTries.Hour);
            Debug.Log("Minutes out of tries: " + dateNoTries.Minute);

            dataGathered = true;
        }
        else {

            Debug.Log("Hours remaining to get new tries: " + (dateNoTries.Hour - currentDate.Hour));
            Debug.Log("Minutes remaining to get new tries: " + (dateNoTries.Minute - currentDate.Minute));
        }
        

    }

}

}

Hi,

If I get you right, this is a very simple math question. Right now, instead of getting 4 hours left, you get 20 hours have passed. You know your tickets refill after 24 hours, you managed to calculate the 20, what you need is four. I’ll let you do the math to go from 24 and 20 to 4 ok? :stuck_out_tongue: good luck!

a much easier version.

using UnityEngine;
using System.Collections;
using System;

public class liveTimer : MonoBehaviour
{
DateTime dateNow;
DateTime dateNoTicket;

public int timeNow;
public int timeToRefill;
public int hourNoTicket;
public int hoursLeft;

public bool refillHourSet;

void Update()
{
    logic();
}

void logic()
{
    if (dataManager.gameDataManager.lottoTries == 0)
    {
        dataManager.gameDataManager.LoadData();
        if (!refillHourSet)
        {
            dateNoTicket = DateTime.Now;
            hourNoTicket = dateNoTicket.Minute;
            refillHourSet = true;
        }
        else {
            dateNow = DateTime.Now;
            timeNow = dateNow.Minute;
        }

        TimeSpan timeDifference = dateNow.Subtract(dateNoTicket);
  

        hoursLeft = 4 - timeDifference.Minutes;

        if (hoursLeft == 0) {
            dataManager.gameDataManager.lottoTries = 1;
            dataManager.gameDataManager.SaveData();
        }

    }
}

}