add time based street light, fix directional room entrance
This commit is contained in:
@@ -7,6 +7,7 @@ public class TimeManager : MonoBehaviour
|
||||
private const int MINUTES_PER_HOUR = 60;
|
||||
public const int SECONDS_PER_MINUTE = 2;
|
||||
|
||||
[SerializeField]
|
||||
private int currentHour = 12;
|
||||
private int currentMinute = 0;
|
||||
private float currentSecond = 0;
|
||||
|
||||
@@ -123,16 +123,6 @@ public void WalkInDirection(Vector3 direction)
|
||||
{
|
||||
Vector3 forwardDir = direction;
|
||||
forwardDir.y = 0; // don't move on the y axis
|
||||
|
||||
if (cameraController != null)
|
||||
{
|
||||
// re-matrix the rotation direction so movement is consistent no matter what
|
||||
// the camera rotation is
|
||||
|
||||
Matrix4x4 matrix = Matrix4x4.Rotate(Quaternion.Euler(0, cameraController.playerCamHome.rotation.eulerAngles.y, 0));
|
||||
forwardDir = matrix.MultiplyPoint3x4(forwardDir);
|
||||
}
|
||||
|
||||
forwardDir *= walkSpeed;
|
||||
|
||||
characterController.Move(forwardDir * Time.deltaTime);
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user