I’ve hit a roadblock in my project. When my character is sleepy (ie. has 300 sleep points out of 1000) and goes to sleep the time goes forward like I want. However, when the character gets sleepy again after that and goes to sleep, instead of adding the hours to the NEW time since his first sleep, the last sleep’s hours are taken off and the new sleep time’s hours are added.
So my question is how can I make gameTimeHour permenantly change in Update()?
public class Clock : MonoBehaviour {
Text text;
DateTime currentTime;
Sleep sleep;
// Use this for initialization
void Start () {
text = FindObjectOfType<Text>();
sleep = FindObjectOfType<Sleep>();
}
// Update is called once per frame
void Update ()
{
numTimesGettingASkill = skills.numSkillTimes;
currentTime = DateTime.Now;
int gameTimeHour = currentTime.Hour;
int gameTimeMinutes = currentTime.Minute;
int gameTimeSeconds = currentTime.Second;
if (sleep.goingToSleep == true)
{
if(sleep.hoursNeededToSleep >= 1)
{
gameTimeHour += Mathf.RoundToInt(sleep.hoursNeededToSleep);
}
else if (sleep.hoursNeededToSleep < 1 && sleep.hoursNeededToSleep > 0)
{
gameTimeHour += 1;
}
else
{
return;
}
}
text.text = gameTimeHour + ":" + gameTimeMinutes + ":" + gameTimeSeconds;
}
}