UnityEngine.Invoke() Doesn't work properly with values under 1?
I'm trying to make a day/night cycle. I have a reference in the inspector where you get to input how many IRL minutes corresponds to an in-game day. So this is what I came up with
[Tooltip("The amount of many real life minutes that will pass in one in-game day")]
public float IRLMinutesPerIngameDay;
float SecondsToPass = 86400f;
float HoursToPass = 24f;
private void Update()
{
float IRLSecondsToPass = IRLMinutesPerIngameDay * 60;
float ratio = IRLSecondsToPass / SecondsToPass;
Invoke("AdvanceTime", 1.0f * ratio);
}
void AdvanceTime() //All you need it know about this method is that it adds +1 to seconds everytime it's called
{
DayEndHour = DayStartHour + HoursOfDaytime;
Season = GetSeason();
Day = GetDay();
//Debug.Log(Hour + ":" + Minute + ":" + Second);
Second += 1;
SecondsPassed += 1;
if (Second >= 60f)
{
Second -= 60;
Minute++;
}
if (Minute >= 60)
{
Minute = 0;
Hour++;
HoursPassed++;
}
if (Hour > 23)
{
Hour = 0;
DayNum++;
}
if (HoursPassed >= HoursToPass)
{
SecondsPassed = 0;
HoursPassed = 0;
}
if (DayNum > SeasonLength * 4)
{
DayNum = 0;
SeasonNum = 1;
}
if (DayNum % SeasonLength == 0)
SeasonNum = DayNum / 4;
SetCorrectSunAngle();
}
So what I tried to do here is to convert a real life second to 1 in-game second and then call the method that advances time every in-game second.
The only result I get is the sun moving very slowly BUT with the same speed whatever value that has been given in the inspector (IRLMinutesPerIngameDay).
I might be missing out on something really simple here but to me it seems like the Invoke() method doesn't work very well with values under 1.0f.
Comment