traingles uvs coordinated with Raycast

Hello,

I want to change the texture of a mesh of triangles. When the play click on a triangle it changes texture. To do this, I use RaycatHit.Triangle and texture Atlas.
The raycatHit.Triangle gives me the local coordinates of the three vertices (correct me if I say stupid because I start :)). My idea is to find the coordinates of the triangle Uvs, or rather three peaks, and change to display the new texture triangle ‘raycaté’. I can not find the coordinates from Uvs Raycast!

Thank you for your help

The RayCast HitInfo structure returns UV coords.

thank you for your answer
the ‘raycastHit.Coord’ returns the coordinates at the point of impact.
I want to have the UV coordinates of the three vertices of the triangle hit by the ray.

The raycast hit contains the index of the triangle. You can them look up the UV’s in from the mesh.

This above example shows how to get the vertices of the hit triangle.

I think you should be able to get the UV’s using something like the following:

Vector2[ ] uv = mesh.uv;
int[ ] triangles = mesh.triangles;
Vector2 p0 = uv[triangles[hit.triangleIndex * 3 + 0]];
Vector2 p1 = uv[triangles[hit.triangleIndex * 3 + 1]];
Vector2 p2 = uv[triangles[hit.triangleIndex * 3 + 2]];

This code isn’t tested.

Thank you, I finally understood :stuck_out_tongue: