반응형
- 코드 작성
using UnityEngine;
public class RaycastExample : MonoBehaviour
{
[SerializeField] private LayerMask layerMask;
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hitInfo, Mathf.Infinity, layerMask))
{
Debug.Log("Hit object: " + hitInfo.collider.gameObject.name);
}
}
}
}
반응형