Simple Day Night Cycle Efficiency Check
Hi there, I'm looking to make a game in which the time of day can determine an npc's behavior. I wrote a little script that will keep track of time, but it may be relying on the Update method a bit too much. Is there a better place I can put my code for best practice?
public class TimeKeeper : MonoBehaviour
{
public float currentTime;
public string partOfDay;
private void Start()
{
partOfDay = "morning";
}
void Update()
{
currentTime = Time.time;
if (currentTime > 50 && (partOfDay == "morning"))
{
partOfDay = "noon";
SetRoutine();
}
if (currentTime > 100 && (partOfDay == "noon"))
{
partOfDay = "night";
SetRoutine();
}
if (currentTime > 150 && (partOfDay == "night"))
{
partOfDay = "morning";
SetRoutine();
//currentTime = 0;
}
}
void SetRoutine()
{
//This is where I will update the NPC's to move to a new location
Debug.Log ("the time has changed to " + partOfDay);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613001640im_/https://answers.unity.com/themes/thub/images/avi.jpg)