added PartsOfDay

This commit is contained in:
j.mei7
2022-02-18 22:00:50 +01:00
parent a01c75c28e
commit a3db54a9b9

View File

@@ -3,13 +3,23 @@ using UnityEngine;
public class TimeManager : MonoBehaviour
{
public enum PartOfDay
{
MORNING,
AFTERNOON,
EVENING,
NIGHT
}
public PartOfDay partOfDay;
[SerializeField]
float intervalTime = 1.0f; // 1.0f -> 1 real second is 1 ingame minute
[SerializeField]
int minutesPerInterval = 1;
DateTime dateTime = new DateTime(1, 1, 1, 0, 0, 0);
DateTime dateTime = new DateTime(1, 1, 1, 23, 0, 0);
public DateTime GetDateTime() => dateTime;
public string GetTime() => dateTime.ToString("hh:mm tt");
@@ -23,6 +33,24 @@ public class TimeManager : MonoBehaviour
void TimeUp()
{
dateTime = dateTime.AddMinutes(minutesPerInterval);
CheckPartsOfDay();
Debug.Log(GetTime());
}
void CheckPartsOfDay()
{
Debug.Log(dateTime.Hour);
if (dateTime.Hour >= 22)
partOfDay = PartOfDay.NIGHT;
else if(dateTime.Hour < 6)
partOfDay = PartOfDay.NIGHT;
else if (dateTime.Hour >= 6 && dateTime.Hour < 12)
partOfDay = PartOfDay.MORNING;
else if (dateTime.Hour >= 12 && dateTime.Hour < 17)
partOfDay = PartOfDay.AFTERNOON;
else if (dateTime.Hour >= 17 && dateTime.Hour < 22)
partOfDay = PartOfDay.EVENING;
}
// For Plant growth maybe add a List<GameObject/Script> where those plants can register themselves and every "TimeUp()" they get checked by the TimeManager