using UnityEngine; public class DayNightCycle : MonoBehaviour { [Header("Lights")] public Transform sunLight; public Transform moonLight; [Header("Skybox Materials")] public Material daySkybox; public Material nightSkybox; [Header("Rotation Settings")] public float startRotationX = 10f; public float endRotationX = 350f; [Range(0, 1)] public float duskPercentage = 0.5f; private bool hasTriggeredDusk = false; void Update() { if (GameManager.Instance != null) { float totalDayTime = 300f; float timePassed = totalDayTime - GameManager.Instance.timeRemaining; float timePercentage = timePassed / totalDayTime; // 1. Handle Light Rotation float currentSunX = Mathf.Lerp(startRotationX, endRotationX, timePercentage); sunLight.rotation = Quaternion.Euler(currentSunX, -30f, 0f); moonLight.rotation = Quaternion.Euler(currentSunX + 180f, -30f, 0f); // 2. Handle Skybox Swap // We swap to the night skybox a bit before the dusk enemies spawn if (timePercentage > 0.45f) { RenderSettings.skybox = nightSkybox; } else { RenderSettings.skybox = daySkybox; } // 3. Dusk Enemies Trigger if (timePercentage >= duskPercentage && !hasTriggeredDusk) { hasTriggeredDusk = true; TerrainObjectSpawner spawner = FindObjectOfType(); if (spawner != null) spawner.SpawnExtraEnemies(2); } } } }