add time based street light, fix directional room entrance
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user