go through dah doors
bruh bur
This commit is contained in:
@@ -3,6 +3,7 @@ using Unity.Cinemachine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using System.Collections;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
@@ -20,9 +21,9 @@ public class CameraController : MonoBehaviour
|
||||
|
||||
[Header("UI Setup")]
|
||||
public Button talkButton;
|
||||
public Button doorButton; // New button for the doors
|
||||
public Button doorButton;
|
||||
private GuardManager currentGuardManager;
|
||||
private DoorManager currentDoorManager; // New reference for the door
|
||||
private DoorManager currentDoorManager;
|
||||
|
||||
[Header("Hover Highlight Settings")]
|
||||
public Color highlightColour = Color.yellow;
|
||||
@@ -38,19 +39,17 @@ public class CameraController : MonoBehaviour
|
||||
public float focusNudgeSpeed = 5f;
|
||||
public float maxFocusOffset = 2f;
|
||||
|
||||
// Exploration rotation tracker (Horizontal only now)
|
||||
private Quaternion startingRotation;
|
||||
private float currentYaw = 0f;
|
||||
|
||||
// Ping-Pong Focus Trackers
|
||||
private bool useCameraA = true;
|
||||
private Transform dynamicFocusTargetA;
|
||||
private Transform dynamicFocusTargetB;
|
||||
private Transform activeDynamicTarget;
|
||||
private Transform currentInteractableTransform;
|
||||
|
||||
// Focus offset (Horizontal only now)
|
||||
private float currentFocusOffsetX = 0f;
|
||||
private bool isSequencePlaying = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -77,7 +76,7 @@ public class CameraController : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Mouse.current == null) return;
|
||||
if (Mouse.current == null || isSequencePlaying) return;
|
||||
|
||||
HandleHover();
|
||||
HandleEdgeNudge();
|
||||
@@ -86,8 +85,6 @@ public class CameraController : MonoBehaviour
|
||||
{
|
||||
if (EventSystem.current != null && EventSystem.current.IsPointerOverGameObject())
|
||||
{
|
||||
// TRIPWIRE 1: ADD THIS LINE HERE
|
||||
Debug.Log("⚠️ Click cancelled! The EventSystem thinks your mouse is hovering over a UI element.");
|
||||
return;
|
||||
}
|
||||
HandleInteractionClick();
|
||||
@@ -109,7 +106,6 @@ public class CameraController : MonoBehaviour
|
||||
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||
float yawInput = 0f;
|
||||
|
||||
// Check horizontal edges only
|
||||
if (mousePos.x < edgeThickness) yawInput = -1f;
|
||||
else if (mousePos.x > Screen.width - edgeThickness) yawInput = 1f;
|
||||
|
||||
@@ -122,7 +118,6 @@ public class CameraController : MonoBehaviour
|
||||
currentFocusOffsetX += yawInput * focusNudgeSpeed * Time.deltaTime;
|
||||
currentFocusOffsetX = Mathf.Clamp(currentFocusOffsetX, -maxFocusOffset, maxFocusOffset);
|
||||
|
||||
// Move the invisible point horizontally relative to the camera
|
||||
activeDynamicTarget.position = currentInteractableTransform.position
|
||||
+ (mainUnityCamera.transform.right * currentFocusOffsetX);
|
||||
}
|
||||
@@ -161,17 +156,6 @@ public class CameraController : MonoBehaviour
|
||||
originalColour = currentlyHoveredRenderer.material.color;
|
||||
currentlyHoveredRenderer.material.color = highlightColour;
|
||||
}
|
||||
|
||||
|
||||
if (currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != null)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>().isfocussed = 1;
|
||||
}
|
||||
|
||||
if (currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>() != null)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<GuardManager>().isfocussed = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -192,23 +176,6 @@ public class CameraController : MonoBehaviour
|
||||
{
|
||||
currentlyHoveredRenderer.material.color = originalColour;
|
||||
}
|
||||
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>() != currentDoorManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponentInParent<DoorManager>().isfocussed = 0;
|
||||
}
|
||||
|
||||
if (
|
||||
currentlyHoveredRenderer.gameObject.GetComponent<GuardManager>() != null &&
|
||||
currentlyHoveredRenderer.gameObject.GetComponent<GuardManager>() != currentGuardManager
|
||||
)
|
||||
{
|
||||
currentlyHoveredRenderer.gameObject.GetComponent<GuardManager>().isfocussed = 0;
|
||||
}
|
||||
|
||||
currentlyHoveredRenderer = null;
|
||||
}
|
||||
}
|
||||
@@ -220,9 +187,6 @@ public class CameraController : MonoBehaviour
|
||||
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||
{
|
||||
// TRIPWIRE 2: ADD THIS LINE HERE
|
||||
Debug.Log($"🎯 Raycast successfully hit: {hit.transform.name}");
|
||||
|
||||
currentInteractableTransform = hit.transform;
|
||||
currentFocusOffsetX = 0f;
|
||||
|
||||
@@ -230,13 +194,6 @@ public class CameraController : MonoBehaviour
|
||||
CinemachineCamera oldCam = useCameraA ? focusCameraB : focusCameraA;
|
||||
Transform nextTarget = useCameraA ? dynamicFocusTargetA : dynamicFocusTargetB;
|
||||
|
||||
// TRIPWIRE 3: ADD THIS SAFETY CHECK HERE
|
||||
if (nextCam == null)
|
||||
{
|
||||
Debug.LogError("🚨 ERROR: One of your Focus Cameras is missing in the GameManager Inspector!");
|
||||
return;
|
||||
}
|
||||
|
||||
nextTarget.position = currentInteractableTransform.position;
|
||||
nextCam.Follow = currentInteractableTransform;
|
||||
nextCam.LookAt = nextTarget;
|
||||
@@ -247,39 +204,26 @@ public class CameraController : MonoBehaviour
|
||||
activeDynamicTarget = nextTarget;
|
||||
useCameraA = !useCameraA;
|
||||
|
||||
// Logic to determine which UI button to show
|
||||
GuardManager guard = hit.transform.GetComponent<GuardManager>();
|
||||
DoorManager door = hit.transform.GetComponent<DoorManager>();
|
||||
|
||||
// Hide both first to be safe, then reveal the correct one
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
|
||||
UnsetAll();
|
||||
currentDoorManager = null;
|
||||
currentGuardManager = null;
|
||||
|
||||
if (guard != null)
|
||||
{
|
||||
AudioManager.Instance.PlaySound("WordAdd");
|
||||
currentGuardManager = guard;
|
||||
guard.isfocussed = 2;
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(true);
|
||||
}
|
||||
else if (door != null)
|
||||
{
|
||||
AudioManager.Instance.PlaySound("WordAdd");
|
||||
currentDoorManager = door;
|
||||
door.isfocussed = 2;
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// TRIPWIRE 4: ADD THIS LINE HERE
|
||||
Debug.Log("💨 Raycast hit nothing on the Interactable layer. Returning to main camera.");
|
||||
ReturnToMainCamera();
|
||||
AudioManager.Instance.PlaySound("WordRemove");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,19 +231,63 @@ public class CameraController : MonoBehaviour
|
||||
{
|
||||
if (currentGuardManager != null)
|
||||
{
|
||||
AudioManager.Instance.PlaySound("Select");
|
||||
DialogManager.Instance.StartDialog(currentGuardManager);
|
||||
//talkButton.gameObject.SetActive(false);
|
||||
talkButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDoorButtonClicked()
|
||||
{
|
||||
if (currentDoorManager != null)
|
||||
if (currentDoorManager != null && currentDoorManager.doorCamera != null && currentDoorManager.doorSplineDolly != null)
|
||||
{
|
||||
// Add your door sequence logic here!
|
||||
Debug.Log("Door sequence started!");
|
||||
//doorButton.gameObject.SetActive(false);
|
||||
doorButton.gameObject.SetActive(false);
|
||||
StartCoroutine(DoorSequenceRoutine(currentDoorManager));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("The DoorManager is missing its Camera or Spline Dolly references!");
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator DoorSequenceRoutine(DoorManager activeDoor)
|
||||
{
|
||||
isSequencePlaying = true;
|
||||
RemoveHighlight();
|
||||
|
||||
activeDoor.doorSplineDolly.CameraPosition = 0f;
|
||||
activeDoor.doorCamera.Priority = 30;
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
float pushSpeed = 0.5f;
|
||||
|
||||
// Push the camera through the doorway
|
||||
while (activeDoor.doorSplineDolly.CameraPosition < 1f)
|
||||
{
|
||||
activeDoor.doorSplineDolly.CameraPosition += pushSpeed * Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
activeDoor.doorSplineDolly.CameraPosition = 1f;
|
||||
|
||||
yield return new WaitForSeconds(2.0f);
|
||||
|
||||
// The camera is now inside the room. Let's check what kind of door it was!
|
||||
if (activeDoor.type == "LIFE")
|
||||
{
|
||||
Debug.Log("Safe door chosen! Advancing to the next level.");
|
||||
GlobalStateManager.Instance.SetLevelCompleted(GlobalStateManager.Instance.LevelIntended);
|
||||
}
|
||||
else if (activeDoor.type == "DEATH")
|
||||
{
|
||||
Debug.Log("Wrong door! The player has met a grim fate.");
|
||||
|
||||
// Add your death screen or level restart logic here!
|
||||
// For example: GlobalStateManager.Instance.TriggerGameOver();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Door type '{activeDoor.type}' is not recognised for level transitions.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,7 +304,6 @@ public class CameraController : MonoBehaviour
|
||||
currentGuardManager = null;
|
||||
currentDoorManager = null;
|
||||
|
||||
UnsetAll();
|
||||
if (talkButton != null) talkButton.gameObject.SetActive(false);
|
||||
if (doorButton != null) doorButton.gameObject.SetActive(false);
|
||||
}
|
||||
@@ -333,17 +320,4 @@ public class CameraController : MonoBehaviour
|
||||
explorationCamera.transform.rotation = startingRotation;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnsetAll()
|
||||
{
|
||||
foreach (var doorManager in LevelLoader.Instance.Doors)
|
||||
{
|
||||
doorManager.isfocussed = 0;
|
||||
}
|
||||
foreach (var doorManager in LevelLoader.Instance.Guards)
|
||||
{
|
||||
doorManager.isfocussed = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user