Check if x hours passed since Y event

Hey,

umm I have something like a crystal that player can pick up, but it must regenerate in X hours of real time.

How can I capture system time and then compare it to current system time to see if X hours have passed between these two ?

I found the System.DateTime.Now but I’m not sure how can I nail check if x hours passed with that.

Thanks in advance.

My solution would be, you start the cooldown on use. Before the game is closed, you write the remaining cooldown to a file, to the user preferences or in a different form.

When the game starts again, you read the file, substract its value from the current System.DateTime and see if the difference is equal or bigger than the cooldown time.

This’s my suggestion. Not sure if the best.

private int hours = 0, minutes = 0, x = 3; // x is your X hours
private float seconds = 0;
private bool objectPicked = false;

void Update(){
if(objectPicked)
{
seconds += Time.deltaTime;
if(seconds > 60)
{
minutes++;
seconds = 0;
}
if(minutes > 60)
{
hours++;
minutes = 0;
}
if(hours >= x)
{
// regen life here
objectPicked = false;
hours = 0; minutes = 0; seconds = 0;
}
}
}

And you just need to add this:
objectPicked = true;
when the user picks up the object.