diff --git a/Game/Assets/Scenes/0_MainScene.unity b/Game/Assets/Scenes/0_MainScene.unity index f411017..0d0472d 100644 --- a/Game/Assets/Scenes/0_MainScene.unity +++ b/Game/Assets/Scenes/0_MainScene.unity @@ -4347,6 +4347,7 @@ GameObject: - component: {fileID: 750131492} - component: {fileID: 750131491} - component: {fileID: 750131493} + - component: {fileID: 750131494} m_Layer: 0 m_Name: CinemachineCamera m_TagString: Untagged @@ -4432,6 +4433,18 @@ MonoBehaviour: RotationDamping: {x: 0, y: 0, z: 0} QuaternionDamping: 1 FollowOffset: {x: 0, y: 0, z: -10} +--- !u!114 &750131494 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 750131489} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f0a87a1c7758eb34587daa15a89d59d4, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::DownwardCamera --- !u!1001 &751558359 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Game/Assets/Scripts/Camera.cs b/Game/Assets/Scripts/Camera.cs new file mode 100644 index 0000000..1c8da22 --- /dev/null +++ b/Game/Assets/Scripts/Camera.cs @@ -0,0 +1,43 @@ +using UnityEngine; +using Unity.Cinemachine; + +public class DownwardCamera : CinemachineExtension +{ + private float minY; + private bool isInitialized = false; + + protected override void PostPipelineStageCallback( + CinemachineVirtualCameraBase vcam, + CinemachineCore.Stage stage, + ref CameraState state, + float deltaTime) + { + if (stage == CinemachineCore.Stage.Body) + { + Vector3 pos = state.RawPosition; + + if (!isInitialized) + { + minY = pos.y; + isInitialized = true; + } + + if (pos.y < minY) + { + minY = pos.y; + } + // If it tries to move UP (higher Y), lock it to the lowest point we've reached + else + { + pos.y = minY; + } + + state.RawPosition = pos; + } + } + + public void ResetCamera() + { + isInitialized = false; + } +} \ No newline at end of file diff --git a/Game/Assets/Scripts/Camera.cs.meta b/Game/Assets/Scripts/Camera.cs.meta new file mode 100644 index 0000000..1c69e76 --- /dev/null +++ b/Game/Assets/Scripts/Camera.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: f0a87a1c7758eb34587daa15a89d59d4 \ No newline at end of file