DayNightCycle.cs 853 B

12345678910111213141516171819202122232425
  1. using UnityEngine;
  2. public class DayNightCycle : MonoBehaviour
  3. {
  4. [Header("Rotation Settings")]
  5. public float startRotationX = 10f; // Morning sun angle
  6. public float endRotationX = 180f; // Sunset/Night angle
  7. void Update()
  8. {
  9. if (GameManager.Instance != null)
  10. {
  11. // Calculate how much time has passed as a percentage (0 to 1)
  12. float totalDayTime = 300f;
  13. float timePassed = totalDayTime - GameManager.Instance.timeRemaining;
  14. float timePercentage = timePassed / totalDayTime;
  15. // Interpolate the rotation from morning to night
  16. float currentRotationX = Mathf.Lerp(startRotationX, endRotationX, timePercentage);
  17. // Apply rotation to the light
  18. transform.rotation = Quaternion.Euler(currentRotationX, -30f, 0f);
  19. }
  20. }
  21. }