first commit
This commit is contained in:
39
Assets/Scripts/RaycastDebugge.cs
Normal file
39
Assets/Scripts/RaycastDebugge.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class RaycastDebugge : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float distance = 200f;
|
||||
[SerializeField] private LayerMask mask = ~0;
|
||||
|
||||
private Camera _camera;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_camera = GetComponent<Camera>();
|
||||
if (_camera == null)
|
||||
Debug.LogError("RaycastDebugger: logic error.");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (_camera == null) return;
|
||||
|
||||
Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
Debug.DrawRay(ray.origin, ray.direction * 5f, Color.red);
|
||||
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
if (Physics.Raycast(ray, out RaycastHit hit, distance, mask, QueryTriggerInteraction.Collide))
|
||||
{
|
||||
Debug.Log($"CLICK HIT: {hit.collider.name} | tag={hit.collider.tag} | layer={LayerMask.LayerToName(hit.collider.gameObject.layer)} | dist={hit.distance:F2}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("CLICK HIT: nothing");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user