Time Management. Morning, noon and night.
Hi I am still very new to unity and was hoping to have someone point me to a tutorial or helpful hint that may help me out. :) Im trying to create a game that progresses time only when an action is done. Example, the player chooses to go to the shops in the morning so the game progresses to noon where they can choose another action. Ive tried to look for tutorials in time management but can only manage to find the real-time progression ones. Thanks :)
Answer by Alanisaac · Feb 18, 2018 at 10:23 PM
What I would do is use an enum to represent the time of day. I wrote an example script, showing how you can use a TimeManager class to progress to the next time of day (as well as keep track of how many days are elapsed). There's example usage of both, but the examples are very simple -- you'll need to figure out how you want to use the time of day and when you want your player to progress in your own game:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum TimeOfDay
{
Morning,
Noon,
Night
}
public static class TimeManager
{
public static int DaysElapsed { get; private set; }
public static TimeOfDay CurrentTimeOfDay { get; private set; }
public static void ProgressToNextTime()
{
switch(CurrentTimeOfDay)
{
case TimeOfDay.Morning:
CurrentTimeOfDay = TimeOfDay.Noon;
break;
case TimeOfDay.Noon:
CurrentTimeOfDay = TimeOfDay.Night;
break;
case TimeOfDay.Night:
CurrentTimeOfDay = TimeOfDay.Morning;
DaysElapsed = DaysElapsed + 1;
break;
}
}
}
// an example class doing something with the time
public class GameManager : MonoBehaviour
{
// an example of using the time of day to return something different
// your real "GetActions" would probably return a list of Action classes or something similar
public string GetAction()
{
var currentTimeOfDay = TimeManager.CurrentTimeOfDay;
switch(currentTimeOfDay)
{
case TimeOfDay.Morning:
return "Breakfast";
case TimeOfDay.Noon:
return "Lunch";
case TimeOfDay.Night:
return "Dinner";
default:
return string.Empty;
}
}
// an example of incrementing the time after an action
public void DoAction(string action)
{
// here, the player's action is just printing debug info
Debug.Log("Player did the action: " + action);
// after the player does the action, use this to increment the time
TimeManager.ProgressToNextTime();
}
}
Answer by Palanquinsg245 · Apr 22 at 10:46 AM
You know, the only thing I can advise you is to read some essays on time management. Here (https://papersowl.com/examples/time-management/) for example, you can read, see how people do, and learn about their experiences. In my opinion, this is better than any book. After all, experience immediately shows how to act, and how not.
Your answer
Follow this Question
Related Questions
Clock doesn't stop when reaches 0.0. Can you help me with this. 1 Answer
How to create a timer that only increases when if command is true? 1 Answer
why the Timer isn't working 0 Answers
I make a timing score script in unity 2D, how i make high score of time?? Script is as follow: 1 Answer
Code Help Needed. Anti-Time Cheat System Not Working !!! 0 Answers