Files
Emberwild/Assets/External/NV3D/Shatter Stone/Shared/Scripts/DemoClickInteraction.cs
T
Mathew 78bfdf2828 Merge remote-tracking branch 'origin/feat/inport-props' into feat/craft-discovery
# Conflicts:
#	Assets/External/Animated PBR Chest Demo/Materials/WoodChest.mat
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for BiRP.unitypackage.meta
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for HDRP.unitypackage.meta
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for URP.unitypackage.meta
2026-07-25 19:42:26 +02:00

62 lines
1.9 KiB
C#

// This script is used in the demo scene to allow on-click interactions with the Shatter Stone ore nodes.
// It supports both Unity's old Input Manager and the new Input System.
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace ShatterStone
{
public class DemoClickInteraction : MonoBehaviour
{
[SerializeField] private Camera mainCamera;
[SerializeField] private float maxDistance = 100f;
[Tooltip("Tag used to identify ore nodes in the scene.")]
[SerializeField] private string oreNodeTag = "OreNode";
[SerializeField] private string orePickupTag = "OrePickup";
private void Update()
{
// Check input based on the input system available
bool inputPressed = false;
Vector2 pointerPos = default;
#if ENABLE_INPUT_SYSTEM
if (Mouse.current != null && Mouse.current.leftButton.wasPressedThisFrame)
{
inputPressed = true;
pointerPos = Mouse.current.position.ReadValue();
}
#else
if (Input.GetMouseButtonDown(0))
{
inputPressed = true;
pointerPos = Input.mousePosition;
}
#endif
if (!inputPressed) return;
Ray ray = mainCamera.ScreenPointToRay(pointerPos);
if (Physics.Raycast(ray, out RaycastHit hit, maxDistance))
{
if (hit.collider.CompareTag(oreNodeTag))
{
var oreNode = hit.collider.GetComponent<OreNode>();
oreNode?.Interact();
}
if (hit.collider.CompareTag(orePickupTag))
{
var orePickup = hit.collider.GetComponent<PickupController>();
orePickup?.CollectItem();
}
}
}
}
}