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

32 lines
728 B
C#
Raw Normal View History

2024-04-20 01:51:12 +02:00
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>();
2024-04-20 15:38:21 +02:00
slotInfo.OnClick();
2024-04-20 01:51:12 +02:00
Debug.Log($"Hit PlacementSlot! At ({slotInfo.x}, {slotInfo.y})");
}
}
}