// Update is called once per frame void Update() { if (SunObject == null) { SunObject = Instantiate(SunPrefab); } AdjustedTimeElapsed += Time.deltaTime * timeRatio; CurrentTime.AddMinutes(((int)(AdjustedTimeElapsed)) % (60 * 24)); float TimeMinutes = CurrentTime.ToMinutes(); float proportionTime = 0f; if (TimeMinutes > (SunriseTime.ToMinutes() - SunriseDuration.ToMinutes() / 2) && TimeMinutes < SunriseTime.ToMinutes()) { proportionTime = TimeMinutes - (SunriseTime.ToMinutes() - SunriseDuration.ToMinutes() / 2); setColor(Color.Lerp(nightColor, dawnColor, (proportionTime) / (SunriseDuration.ToMinutes() / 2))); } else if (TimeMinutes < (SunriseTime.ToMinutes() + SunriseDuration.ToMinutes() / 2) && TimeMinutes > SunriseTime.ToMinutes()) { proportionTime = TimeMinutes - (SunriseTime.ToMinutes()); setColor(Color.Lerp(dawnColor, dayColor, (proportionTime) / (SunriseDuration.ToMinutes() / 2))); } if (TimeMinutes > (SunsetTime.ToMinutes() - SunriseDuration.ToMinutes() / 2) && TimeMinutes < SunsetTime.ToMinutes()) { proportionTime = TimeMinutes - (SunsetTime.ToMinutes() - SunriseDuration.ToMinutes() / 2); setColor(Color.Lerp(dayColor, duskColor, (proportionTime) / (SunriseDuration.ToMinutes() / 2))); } else if (TimeMinutes < (SunsetTime.ToMinutes() + SunriseDuration.ToMinutes() / 2) && TimeMinutes > SunsetTime.ToMinutes()) { proportionTime = TimeMinutes - (SunsetTime.ToMinutes()); setColor(Color.Lerp(duskColor, nightColor, (proportionTime) / (SunriseDuration.ToMinutes() / 2))); } SunObject.transform.rotation = Quaternion.Euler(35f, Mathf.Lerp(-50, 50, TimeMinutes / (24 * 60)), 0f); }