using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; public class CameraSlotClickDetect : MonoBehaviour { public Camera mainCamera; public LayerMask layerMask; private SlotManager PrevHoveredSlot; void Update() { if (Input.GetMouseButtonDown(0)) { ShootClickRay(); } ShootHoverRay(); } void ShootClickRay() { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { var slotInfo = hit.collider.gameObject.GetComponentInParent(); slotInfo.OnClick(); } } void ShootHoverRay() { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { var slotInfo = hit.collider.gameObject.GetComponentInParent(); if (PrevHoveredSlot != null && PrevHoveredSlot != slotInfo) { PrevHoveredSlot.OnUnHovered(); } slotInfo.OnHovered(); PrevHoveredSlot = slotInfo; } else { PrevHoveredSlot = null; } } }