I am attempting to calculate something based on the amount of time sence the game has last been closed. I have found that there is a really nice function that i can use that is Time.realTimeSensceStartUp; that is great and tracks the time from start up… I was just wondering if there was a nice built in function i could use to track the time sence the last exit of the game. Or would i just need to write my own function that saved the time of exit somehow and subtracted it from the next time on opening?
thanks i actually just stumbled upon that, what namespace do i need to use to allow me to access the DateTime. functions? i have not been able to work it out. i thought just adding "Using System.Net; " would let me use it but it has not.
System.DateTime is the class that is returned by System.DateTime.Now. When I’ve done this in the past, I’ve stored and used System.DateTime.Now.Ticks which is a long int (there are 100,000 of them in 1 second IIRC) - store it as a long, subtract the new one (again as a long), divide by 100000, and boom, you’ve got the number of seconds that have elapsed.
this sounds so much simpler then i am making it… Not sure why i am not quiet getting this… I will keep working on it, could you give me snipit of how you would do the division? for some reason i keep bugging out when i try to divide anything here.
It’s not unreasonable for this to be difficult in practice - you have to make sure that your numbers are exactly the right type every step of the way, or you’ll lose data and your numbers will get weird. Unfortunately I don’t have the script I used at the time (it was at my last job).
Just make sure that you subtract the previous time from the current time before you deal with anything that’s not a long; from there I think I divided it by 1000 to get it to hundredths of seconds, then converted that to a float, then divided that float by 100f. I believe that was enough to avoid range problems.
If that doesn’t help, I will try to answer more specific questions you have about it.