add time based street light, fix directional room entrance

This commit is contained in:
2026-03-17 23:12:13 -05:00
parent 87527b70f7
commit 069cfdd953
7 changed files with 51 additions and 12 deletions
@@ -0,0 +1,33 @@
using System;
using UnityEngine;
public class SunRotation : MonoBehaviour
{
Light directionalLight;
public float offset = 270f; // Adjust for sunrise/sunset timing
void Start()
{
directionalLight = GetComponent<Light>();
}
void Update()
{
DateTime dateTime = new DateTime(
DateTime.Today.Year,
DateTime.Today.Month,
DateTime.Today.Day,
GameManager.Instance.TimeManager.GetCurrentHour(),
GameManager.Instance.TimeManager.GetCurrentMinute(), 0);
// Get current time and convert to a fraction of a day (0 to 1)
float timeOfDay = (float)dateTime.TimeOfDay.TotalDays;
float sunRotation = timeOfDay * 360f + offset;
transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(sunRotation, 0, 0), 10);
// adjust light intensity based on sun height
float sunElevation = Mathf.Sin(sunRotation * Mathf.Deg2Rad);
directionalLight.intensity = Mathf.Max(0, sunElevation);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1df4995bc2c404c47986a4f90cf3ca4f