From 069cfdd953b5f030bfc5bdfadb8d32ab68d13827 Mon Sep 17 00:00:00 2001 From: Trey Shaw Date: Tue, 17 Mar 2026 23:12:13 -0500 Subject: [PATCH] add time based street light, fix directional room entrance --- Assets/Scenes/TestScene2.unity | 17 +++++++++- Assets/Scripts/Management/TimeManager.cs | 1 + Assets/Scripts/PlayerController.cs | 10 ------ .../WorldInteraction}/SunRotation.cs | 2 +- .../WorldInteraction}/SunRotation.cs.meta | 0 Assets/Streetlight.cs | 31 +++++++++++++++++++ Assets/Streetlight.cs.meta | 2 ++ 7 files changed, 51 insertions(+), 12 deletions(-) rename Assets/{ => Scripts/WorldInteraction}/SunRotation.cs (96%) rename Assets/{ => Scripts/WorldInteraction}/SunRotation.cs.meta (100%) create mode 100644 Assets/Streetlight.cs create mode 100644 Assets/Streetlight.cs.meta diff --git a/Assets/Scenes/TestScene2.unity b/Assets/Scenes/TestScene2.unity index 0ca5695..46ff637 100644 --- a/Assets/Scenes/TestScene2.unity +++ b/Assets/Scenes/TestScene2.unity @@ -1070,6 +1070,7 @@ GameObject: - component: {fileID: 410087041} - component: {fileID: 410087040} - component: {fileID: 410087042} + - component: {fileID: 410087043} m_Layer: 0 m_Name: Directional Light m_TagString: Untagged @@ -1186,6 +1187,20 @@ MonoBehaviour: m_ShadowLayerMask: 1 m_RenderingLayers: 1 m_ShadowRenderingLayers: 1 +--- !u!114 &410087043 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 410087039} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1df4995bc2c404c47986a4f90cf3ca4f, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::SunRotation + directionalLight: {fileID: 0} + offset: 270 --- !u!1 &430850200 GameObject: m_ObjectHideFlags: 0 @@ -2838,7 +2853,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 1b892c02d92dd70419f61cf0ae34b9d8, type: 3} m_Name: m_EditorClassIdentifier: Assembly-CSharp::TimeManager - TEST_TEXT_BOX: {fileID: 0} + currentHour: 12 --- !u!1 &986462055 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Management/TimeManager.cs b/Assets/Scripts/Management/TimeManager.cs index d052167..cd06685 100644 --- a/Assets/Scripts/Management/TimeManager.cs +++ b/Assets/Scripts/Management/TimeManager.cs @@ -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; diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 4560aa0..6ad3c05 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -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); diff --git a/Assets/SunRotation.cs b/Assets/Scripts/WorldInteraction/SunRotation.cs similarity index 96% rename from Assets/SunRotation.cs rename to Assets/Scripts/WorldInteraction/SunRotation.cs index d1e5c9a..0a61a1e 100644 --- a/Assets/SunRotation.cs +++ b/Assets/Scripts/WorldInteraction/SunRotation.cs @@ -3,7 +3,7 @@ public class SunRotation : MonoBehaviour { - public Light directionalLight; + Light directionalLight; public float offset = 270f; // Adjust for sunrise/sunset timing void Start() diff --git a/Assets/SunRotation.cs.meta b/Assets/Scripts/WorldInteraction/SunRotation.cs.meta similarity index 100% rename from Assets/SunRotation.cs.meta rename to Assets/Scripts/WorldInteraction/SunRotation.cs.meta diff --git a/Assets/Streetlight.cs b/Assets/Streetlight.cs new file mode 100644 index 0000000..0a484b5 --- /dev/null +++ b/Assets/Streetlight.cs @@ -0,0 +1,31 @@ +using System; +using System.Linq; +using UnityEngine; + +public class Streetlight : MonoBehaviour +{ + // Hours that the light starts and ends + public int[] activeHours = { 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6 }; + + Light objectLight; + private float lightIntensity; + + void Start() + { + objectLight = GetComponent(); + lightIntensity = objectLight.intensity; + } + + // Update is called once per frame + void Update() + { + if (activeHours.Contains(GameManager.Instance.TimeManager.GetCurrentHour())) + { + objectLight.intensity = lightIntensity; + } + else + { + objectLight.intensity = 0; + } + } +} diff --git a/Assets/Streetlight.cs.meta b/Assets/Streetlight.cs.meta new file mode 100644 index 0000000..ec36bb0 --- /dev/null +++ b/Assets/Streetlight.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 67529f5a831c7b240bc979c3bd269016 \ No newline at end of file