| 12345678910111213141516171819202122232425 |
- using UnityEngine;
- public class DayNightCycle : MonoBehaviour
- {
- [Header("Rotation Settings")]
- public float startRotationX = 10f; // Morning sun angle
- public float endRotationX = 180f; // Sunset/Night angle
- void Update()
- {
- if (GameManager.Instance != null)
- {
- // Calculate how much time has passed as a percentage (0 to 1)
- float totalDayTime = 300f;
- float timePassed = totalDayTime - GameManager.Instance.timeRemaining;
- float timePercentage = timePassed / totalDayTime;
- // Interpolate the rotation from morning to night
- float currentRotationX = Mathf.Lerp(startRotationX, endRotationX, timePercentage);
- // Apply rotation to the light
- transform.rotation = Quaternion.Euler(currentRotationX, -30f, 0f);
- }
- }
- }
|