为什么OnMouseDown函数的hit.triangleIndex return -1?
Why OnMouseDown function the hit.triangleIndex return -1?
void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 1000.0f))
{
int[] triangles = transform.GetComponent<MeshFilter>().mesh.triangles;
if (hit.triangleIndex != -1 && (hit.triangleIndex * 3) < triangles.Length)
}
当我单击网格上的一个三角形时,有两个三角形使用断点进入函数,但我看到 hit.triangleIndex 是 -1。
在数组三角形中我有 6 个项目:
index 0 = 2
index 1 = 1
index 2 = 0
index 3 = 2
index 4 = 3
index 5 = 1
Triangle index is only valid if the collider that was hit is a
MeshCollider.
void OnMouseDown()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 1000.0f))
{
int[] triangles = transform.GetComponent<MeshFilter>().mesh.triangles;
if (hit.triangleIndex != -1 && (hit.triangleIndex * 3) < triangles.Length)
}
当我单击网格上的一个三角形时,有两个三角形使用断点进入函数,但我看到 hit.triangleIndex 是 -1。
在数组三角形中我有 6 个项目:
index 0 = 2
index 1 = 1
index 2 = 0
index 3 = 2
index 4 = 3
index 5 = 1
Triangle index is only valid if the collider that was hit is a MeshCollider.