# triangleIndex

> The index of the triangle that was hit.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine](/engine/6000.3/script-reference/unityengine.md)
* **Assembly:** UnityEngine.PhysicsModule

```csharp
public int triangleIndex { get; }
```

### Remarks

Triangle index is only valid if the collider that was hit is a [MeshCollider](/engine/6000.3/script-reference/unityengine/meshcollider.md).

```csharp
// This script draws a debug line around mesh triangles
// as you move the mouse over them.
using UnityEngine;
using System.Collections;
using UnityEngine.InputSystem;

public class ExampleClass : MonoBehaviour
{
    Camera cam;

    void Start()
    {
        cam = GetComponent<Camera>();
    }

    void Update()
    {
        RaycastHit hit;
        if (!Physics.Raycast(cam.ScreenPointToRay(Mouse.current.position.ReadValue()), out hit))
            return;

        MeshCollider meshCollider = hit.collider as MeshCollider;
        if (meshCollider == null || meshCollider.sharedMesh == null)
            return;

        Mesh mesh = meshCollider.sharedMesh;
        Vector3[] vertices = mesh.vertices;
        int[] triangles = mesh.triangles;
        Vector3 p0 = vertices[triangles[hit.triangleIndex * 3 + 0]];
        Vector3 p1 = vertices[triangles[hit.triangleIndex * 3 + 1]];
        Vector3 p2 = vertices[triangles[hit.triangleIndex * 3 + 2]];
        Transform hitTransform = hit.collider.transform;
        p0 = hitTransform.TransformPoint(p0);
        p1 = hitTransform.TransformPoint(p1);
        p2 = hitTransform.TransformPoint(p2);
        Debug.DrawLine(p0, p1);
        Debug.DrawLine(p1, p2);
        Debug.DrawLine(p2, p0);
    }
}
```

Additional Resources: [Physics.Raycast](/engine/6000.3/script-reference/unityengine/physics/raycast.md), [Physics.Linecast](/engine/6000.3/script-reference/unityengine/physics/linecast.md), [Physics.RaycastAll](/engine/6000.3/script-reference/unityengine/physics/raycastall.md).
