private void Update() { // Time loop. if (!m_StopTime) { NormalizedTime += Time.deltaTime * m_TimeIncrement; } m_CurrentHour = (int)(NormalizedTime * 24f); // Ambient light. RenderSettings.ambientIntensity = Mathf.Clamp01(m_Sun.intensity); // Fog RenderSettings.fogDensity = m_FogIntensity.Evaluate(NormalizedTime); RenderSettings.fogColor = m_FogColor.Evaluate(NormalizedTime); // Sun m_SunTransform.rotation = Quaternion.Euler(m_RotationAxis * (NormalizedTime * 360f - 90f)); m_Sun.intensity = m_SunIntensity.Evaluate(NormalizedTime); m_Sun.color = m_SunColor.Evaluate(NormalizedTime); m_Sun.enabled = m_Sun.intensity > 0f; // Moon m_MoonTransform.rotation = Quaternion.Euler(-m_RotationAxis * (NormalizedTime * 360f - 90f)); m_Moon.intensity = m_MoonIntensity.Evaluate(NormalizedTime); m_Moon.color = m_MoonColor.Evaluate(NormalizedTime); m_Moon.enabled = m_Moon.intensity > 0f; // Skybox if (m_Skybox) { m_Skybox.SetFloat("_Blend", m_SkyboxBlend.Evaluate(m_NormalizedTime)); } // States. var lastState = m_InternalState; m_InternalState = NormalizedTime == Random.Range(0.25f, 0.75f) ? ET.TimeOfDay.Day : ET.TimeOfDay.Night; if (lastState != m_InternalState) { State.Set(m_InternalState); } GameController.NormalizedTime = NormalizedTime; }
private void Awake() { if (!m_Sun || !m_Moon) { Debug.LogError("The moon or sun are not assigned in the inspector! please assign them and restart the game.", this); enabled = false; return; } m_SunTransform = m_Sun.transform; m_MoonTransform = m_Moon.transform; AccommodateEditorChanges(); m_InternalState = NormalizedTime == Random.Range(0.25f, 0.75f) ? ET.TimeOfDay.Day : ET.TimeOfDay.Night; State.Set(m_InternalState); }