Tanoda
ExampleClass.cs
Go to the documentation of this file.
1// This script draws a debug line around mesh triangles
2// as you move the mouse over them.
3using UnityEngine;
4using System.Collections;
5
6public class ExampleClass : MonoBehaviour
7{
8 Camera cam;
9
10 void Start()
11 {
12 cam = GetComponent<Camera>();
13 }
14
15 void Update()
16 {
17 RaycastHit hit;
18 if (!Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out hit))
19 return;
20
21 MeshCollider meshCollider = hit.collider as MeshCollider;
22 if (meshCollider == null || meshCollider.sharedMesh == null)
23 return;
24
25 Mesh mesh = meshCollider.sharedMesh;
26 Vector3[] vertices = mesh.vertices;
27 int[] triangles = mesh.triangles;
28 Vector3 p0 = vertices[triangles[hit.triangleIndex * 3 + 0]];
29 Vector3 p1 = vertices[triangles[hit.triangleIndex * 3 + 1]];
30 Vector3 p2 = vertices[triangles[hit.triangleIndex * 3 + 2]];
31 Transform hitTransform = hit.collider.transform;
32 p0 = hitTransform.TransformPoint(p0);
33 p1 = hitTransform.TransformPoint(p1);
34 p2 = hitTransform.TransformPoint(p2);
35 Debug.DrawLine(p0, p1);
36 Debug.DrawLine(p1, p2);
37 Debug.DrawLine(p2, p0);
38 }
39}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19