How to access to exactly that material which under RayCast on Multi material mesh?

Hi, all!

I wonder if some one knows how to define which material now under Raycast ray when stay on Multimaterial Mesh. The problem is that: RaycastHit.collider.renderer.sharedMaterial.name аlways returns top material in list of the MeshRenderer componet.

I have got road mesh which consists of several materials: center line with markups, road, crossroad, border and so on.

All of this materials a can reach through this code, very well:

bool 	onGroundDown = Physics.Raycast(position, -up, out hitDown, distance, layerMask);

  Renderer renderer = hitDown.collider.renderer;

  foreach ( Material  sharedMaterial in renderer.sharedMaterials ) {
    Debug.Log("Wheel " + transform.name + " : " + sharedMaterial.name);
  }

but how to access to exactly that material which under RayCast in this moment?

I left Multimaterial mesh example in attach.

489616--17193--$multimateriaexample.JPG

Hello all, problem still persists, sorry for bump thread, is some one for now knows best way to solve it ? :slight_smile: