3DTD/Assets/Scripts/PlacementSystem/CameraSlotClickDetect.cs

32 lines
728 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraSlotClickDetect : MonoBehaviour
{
public Camera mainCamera;
public LayerMask layerMask;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
ShootRay();
}
}
void ShootRay()
{
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
var slotInfo = hit.collider.gameObject.GetComponentInParent<SlotManager>();
slotInfo.OnClick();
Debug.Log($"Hit PlacementSlot! At ({slotInfo.x}, {slotInfo.y})");
}
}
}