Merge branch 'master' of github.com:WillJeynes/Brackeys2026-2
This commit is contained in:
@@ -13,7 +13,7 @@ GameObject:
|
|||||||
- component: {fileID: 2331016541601695679}
|
- component: {fileID: 2331016541601695679}
|
||||||
- component: {fileID: 7866095202227853034}
|
- component: {fileID: 7866095202227853034}
|
||||||
- component: {fileID: -5178599972986915974}
|
- component: {fileID: -5178599972986915974}
|
||||||
m_Layer: 0
|
m_Layer: 6
|
||||||
m_Name: DoorPrefab
|
m_Name: DoorPrefab
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ GameObject:
|
|||||||
- component: {fileID: 3856222877878501805}
|
- component: {fileID: 3856222877878501805}
|
||||||
- component: {fileID: 2341464222282115151}
|
- component: {fileID: 2341464222282115151}
|
||||||
- component: {fileID: 7100697606801959055}
|
- component: {fileID: 7100697606801959055}
|
||||||
m_Layer: 0
|
m_Layer: 6
|
||||||
m_Name: GuardHat
|
m_Name: GuardHat
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ GameObject:
|
|||||||
- component: {fileID: 2331016541601695679}
|
- component: {fileID: 2331016541601695679}
|
||||||
- component: {fileID: 7866095202227853034}
|
- component: {fileID: 7866095202227853034}
|
||||||
- component: {fileID: 6200014345068414905}
|
- component: {fileID: 6200014345068414905}
|
||||||
m_Layer: 0
|
m_Layer: 6
|
||||||
m_Name: GuardPrefab
|
m_Name: GuardPrefab
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cb32c723ca1b15041b53f25e42df4af6
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using Unity.Cinemachine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
|
public class CameraController : MonoBehaviour
|
||||||
|
{
|
||||||
|
[Header("Cinemachine 3 Setup")]
|
||||||
|
[Tooltip("The single, reusable CinemachineCamera meant for panning to targets.")]
|
||||||
|
public CinemachineCamera focusCamera;
|
||||||
|
|
||||||
|
public int activePriority = 20;
|
||||||
|
public int inactivePriority = 10;
|
||||||
|
|
||||||
|
[Header("Raycast Setup")]
|
||||||
|
public Camera mainUnityCamera;
|
||||||
|
[Tooltip("Put your characters/doors on a specific Layer to ensure we only click them.")]
|
||||||
|
public LayerMask interactableLayer;
|
||||||
|
|
||||||
|
[Header("Hover Highlight Settings")]
|
||||||
|
[Tooltip("The colour the object will turn when hovered.")]
|
||||||
|
public Color highlightColour = Color.yellow;
|
||||||
|
|
||||||
|
// Using 'Renderer' allows this to work on both 3D Meshes and 2D Sprites
|
||||||
|
private Renderer currentlyHoveredRenderer;
|
||||||
|
private Color originalColour;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (Mouse.current == null) return;
|
||||||
|
|
||||||
|
// Check for hovering every frame
|
||||||
|
HandleHover();
|
||||||
|
|
||||||
|
// On Left Mouse Click: Cast the invisible laser
|
||||||
|
if (Mouse.current.leftButton.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
HandleInteractionClick();
|
||||||
|
}
|
||||||
|
|
||||||
|
// On Right Mouse Click: Return to exploration
|
||||||
|
if (Mouse.current.rightButton.wasPressedThisFrame)
|
||||||
|
{
|
||||||
|
ReturnToMainCamera();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleHover()
|
||||||
|
{
|
||||||
|
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||||
|
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||||
|
|
||||||
|
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||||
|
{
|
||||||
|
// Look for any type of renderer (Mesh or Sprite)
|
||||||
|
Renderer hitRenderer = hit.transform.GetComponentInChildren<Renderer>();
|
||||||
|
|
||||||
|
if (hitRenderer != null && hitRenderer != currentlyHoveredRenderer)
|
||||||
|
{
|
||||||
|
RemoveHighlight();
|
||||||
|
|
||||||
|
currentlyHoveredRenderer = hitRenderer;
|
||||||
|
|
||||||
|
// Safely apply the colour tint based on whether it is 2D or 3D
|
||||||
|
if (currentlyHoveredRenderer is SpriteRenderer sprite)
|
||||||
|
{
|
||||||
|
originalColour = sprite.color;
|
||||||
|
sprite.color = highlightColour;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
originalColour = currentlyHoveredRenderer.material.color;
|
||||||
|
currentlyHoveredRenderer.material.color = highlightColour;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RemoveHighlight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemoveHighlight()
|
||||||
|
{
|
||||||
|
if (currentlyHoveredRenderer != null)
|
||||||
|
{
|
||||||
|
// Revert the colour safely
|
||||||
|
if (currentlyHoveredRenderer is SpriteRenderer sprite)
|
||||||
|
{
|
||||||
|
sprite.color = originalColour;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentlyHoveredRenderer.material.color = originalColour;
|
||||||
|
}
|
||||||
|
currentlyHoveredRenderer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleInteractionClick()
|
||||||
|
{
|
||||||
|
// 1. Get the mouse position using the new Input System
|
||||||
|
Vector2 mousePos = Mouse.current.position.ReadValue();
|
||||||
|
Ray ray = mainUnityCamera.ScreenPointToRay(mousePos);
|
||||||
|
|
||||||
|
// 2. Shoot the raycast
|
||||||
|
if (Physics.Raycast(ray, out RaycastHit hit, 100f, interactableLayer))
|
||||||
|
{
|
||||||
|
Transform clickedTarget = hit.transform;
|
||||||
|
|
||||||
|
focusCamera.Follow = clickedTarget;
|
||||||
|
focusCamera.LookAt = clickedTarget;
|
||||||
|
focusCamera.Priority = activePriority;
|
||||||
|
|
||||||
|
Debug.Log($"Successfully panning to: {clickedTarget.name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReturnToMainCamera()
|
||||||
|
{
|
||||||
|
// Dropping the priority below your main exploration camera's priority
|
||||||
|
// will cause the CinemachineBrain to automatically pan back to the player.
|
||||||
|
focusCamera.Priority = inactivePriority;
|
||||||
|
|
||||||
|
// Optional housekeeping: clear the targets whilst dormant
|
||||||
|
focusCamera.Follow = null;
|
||||||
|
focusCamera.LookAt = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d98748519728ab747a66b48c827463cb
|
||||||
Reference in New Issue
Block a user