- Home /
How to use real life timer
What i am trying to do: event in game like a boss spawn, it got killed. the time when it is killed is recorded in real life time. After 24 hours or 6 hours of real life time, it will re-spawn once a player enter the map.
I had read this: http://msdn.microsoft.com/en-us/library/system.datetime.now%28VS.80%29.aspx
I can records the time when boss get killed. do not know how to check if 24 hours or 6 hours has passed after boss gotten kill.
prefer help with the codes in java, or C#
any help would be much appreciated.
Answer by Larry-Dietz · Jan 13, 2012 at 04:28 PM
If you already know how to get the current time with datetime.now, just do the same thing in an update event, and compare the death tiem with the current time, and respawn if the desired time has elapsed.
-Larry
I guess i should say i don't know how to compare them.
DateTime saveTime = DateTime.Now;
then on the update event...
This is the line that i dont know how to code:
if ( (DateTime.Now - saveTime) > 12){
monsterRespawn();}
Try something like...
if ((DateTime.Now-saveTime).Hours > 12){ monsterRespawn(); }
-Larry
Your answer
![](https://koobas.hobune.stream/wayback/20220613062943im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to decrease repeating time in invokerepeating? 2 Answers
How Increase And Decrease And Reset Spawn Rate Over 0 Answers
Decreasing object size until a certain size over time? 2 Answers
Call function only if last call was >= X seconds ago 1 Answer
How increase and decrease and reset spawn rate over time? 1 Answer