Physics.Raycast 버그 잡음

This commit is contained in:
logonkhi
2025-06-24 14:38:58 +09:00
parent fa773ad3a3
commit 3acff06eca
4458 changed files with 3510 additions and 576 deletions

View File

@@ -7,6 +7,9 @@ namespace UVC.Factory.Component
public class ClickTest : MonoBehaviour
{
private InputSystemActions inputSystemActions;
private Camera mainCamera;
//void Start()
//{
// Collider col = GetComponent<Collider>();
@@ -27,68 +30,84 @@ namespace UVC.Factory.Component
// }
//}
//void Update()
//{
// if (Input.GetMouseButtonDown(0)) // 0 represents the left mouse button
// {
void OnMouseDown()
{
Debug.Log($"OnMouseDown: {gameObject.name}");
transform.localScale -= new Vector3(0.05f, 0.05f, 0);
//or
//transform.GetComponent<SpriteRenderer>().color += new Color(40, 40, 40);
}
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit hit;
void OnMouseUp()
{
Debug.Log($"OnMouseUp: {gameObject.name}");
transform.localScale += new Vector3(0.05f, 0.05f, 0);
//or
//transform.GetComponent<SpriteRenderer>().color -= new Color(40, 40, 40);
}
// // 레이 시작점과 방향 로깅
// Debug.Log($"Ray 원점: {ray.origin}, 방향: {ray.direction}");
void Update()
{
if (UnityEngine.Input.GetMouseButtonDown(0)) // 0 represents the left mouse button
{
// // 디버그용 레이를 씬 뷰에 그립니다
// Debug.DrawRay(ray.origin, ray.direction * 100, Color.red, 2f);
Ray ray = Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition);
RaycastHit hit;
// bool hitSomething = Physics.Raycast(ray, out hit);
// Debug.Log($"Mouse button clicked - hit something: {hitSomething}");
// 레이 시작점과 방향 로깅
Debug.Log($"Ray 원점: {ray.origin}, 방향: {ray.direction}");
// if (hitSomething)
// {
// Debug.Log($"Hit object: {hit.collider.gameObject.name}, distance: {hit.distance}, point: {hit.point}");
// }
// else
// {
// // 모든 콜라이더 로깅
// Collider[] allColliders = FindObjectsOfType<Collider>();
// Debug.Log($"씬에 있는 콜라이더 수: {allColliders.Length}");
// 디버그용 레이를 씬 뷰에 그립니다
Debug.DrawRay(ray.origin, ray.direction * 100, Color.red, 60f);
// foreach (var collider in allColliders)
// {
// if (collider.gameObject.activeInHierarchy && collider.enabled)
// Debug.Log($"활성화된 콜라이더: {collider.gameObject.name}, 레이어: {LayerMask.LayerToName(collider.gameObject.layer)}");
// }
// }
bool hitSomething = Physics.Raycast(ray, out hit);
Debug.Log($"Mouse button clicked - hit something: {hitSomething}");
// ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit[] tempinfo = new RaycastHit[100];
// var hitcount = Physics.RaycastNonAlloc(ray, tempinfo, Mathf.Infinity);
// Debug.Log($"Mouse button clicked hitcount:{hitcount} {Physics.Raycast(ray, out hit)}");
if (hitSomething)
{
Debug.Log($"Hit object: {hit.collider.gameObject.name}, distance: {hit.distance}, point: {hit.point}");
}
else
{
// 모든 콜라이더 로깅
Collider[] allColliders = FindObjectsByType<Collider>(FindObjectsSortMode.None);
Debug.Log($"씬에 있는 콜라이더 수: {allColliders.Length}");
// if (Physics.Raycast(ray, out hit))
// {
// // Check if the hit object has the ClickableObject script
// ClickTest clickableObject = hit.collider.GetComponent<ClickTest>();
// if (clickableObject != null)
// {
// // 수동으로 이벤트 호출
// PointerEventData pointerData = new PointerEventData(EventSystem.current);
// pointerData.position = Input.mousePosition;
// OnPointerClick(pointerData);
// }
// else
// {
// Debug.Log("Clicked on: " + hit.collider.gameObject.name + ", but it's not clickable.");
// }
// }
// }
foreach (var collider in allColliders)
{
if (collider.gameObject.activeInHierarchy && collider.enabled)
Debug.Log($"활성화된 콜라이더: {collider.gameObject.name}, 레이어: {LayerMask.LayerToName(collider.gameObject.layer)}");
}
}
// //if (Mouse.current.leftButton.wasPressedThisFrame)
// //{
// // Debug.Log("마우스 클릭 감지");
// //}
//}
ray = Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition);
RaycastHit[] tempinfo = new RaycastHit[100];
var hitcount = Physics.RaycastNonAlloc(ray, tempinfo, Mathf.Infinity);
Debug.Log($"Mouse button clicked hitcount:{hitcount} {Physics.Raycast(ray, out hit)}");
if (Physics.Raycast(ray, out hit))
{
// Check if the hit object has the ClickableObject script
ClickTest clickableObject = hit.collider.GetComponent<ClickTest>();
if (clickableObject != null)
{
// 수동으로 이벤트 호출
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = UnityEngine.Input.mousePosition;
OnPointerClick(pointerData);
}
else
{
Debug.Log("Clicked on: " + hit.collider.gameObject.name + ", but it's not clickable.");
}
}
}
//if (Mouse.current.leftButton.wasPressedThisFrame)
//{
// Debug.Log("마우스 클릭 감지");
//}
}
public void OnPointerClick(PointerEventData eventData)
{