- Home /
Energy refill script bug fix
Hi guys. I am making an energy refill script for my game right now. What it does is it detects whenever the player's energy is below 20 (the maximum amount) and then counts down from 30 seconds. (I've programmed all of the not-in-game stuff and in the real game it's obviously going to take longer than 30 seconds to refill, I've made it 30 seconds for test purposes) However, I find that this doesn't work sometimes and I think i know why. I use DateTime.Now.Second for this a lot and if I exit my game in the second half of a minute, by the time 30 seconds has passed it will already be the beginning of the next minute and the seconds will be lower and therefore will not meet my condition of if (PlayerPrefs.GetInt ("ExitTime") + 30 < System.DateTime.Now.Second) { Reference.energy += 2; }
What property should I use to get the time in seconds which doesn't restart to 0 every minute? Thanks!