Tycoon like game time and date
I am creating a tycoon like game and am not sure how to do the date and time on the game son right now when a new game is created I get the date for now using System.DateTime.Now
and show it on a UI Text but from now on on the game how should the date and time go by of course it shouldn't increase by real time what am exactly trying to do is like how RollerCoasterTycoon World time go by.
So it will be like 5 min in real life will go full day in the game so for example if I started the game now its 10/Sep/2016 after 5 min in real life it will be 11/Sep/2016 in the game and so on.
Answer by Glurth · Sep 10, 2016 at 05:10 PM
I would keep the game's date and time, in it's OWN counter, that I keep track of. The big reason for this is so the user can "pause" the play(sim-progress), and the date counter will NOT continue to progress. Optionally, you could choose to take the Time.timeScale component into effect, if the user can speed up or slow down time in the name. To do this I would check, then update the date counter (gameTimePlayed) like so: (uncompiled/tested, example only)
Start()
{
if(newGameFlag)
{
startDate=System.Time.Now;
gameTimePlayed =0;
}
}
Update()
{
if(!gamePaused)
gameTimePlayed += Time.deltaTime; //Time.deltaTime is affected by unity's TimeScale, there are other Time properties that do not.
}
DateTime GetGameDate()
{
currentDate=startDate;
currentDate.AddSeconds(gameTimePlayed);
return currentDate;
}
Your answer
Follow this Question
Related Questions
Formatting a timespan into a relative date in JavaScript 0 Answers
DateTime.Today for Different Time Zone 1 Answer
Getting the time from a server 2 Answers
Alarm Clock Using System Time 0 Answers
FormatException: String can't convert to DateTime ? 0 Answers