Hi
Is there a way when you use Raycast to know a meshId or subMesh or Materials when the ray intersects any collider
The documentation I only find this
//print("hit.point " +hit.point);
//print("hit.distance " +hit.distance);
//print("hit.normal " +hit.normal);
//print("hit.triangleIndex " +hit.triangleIndex);
//print("hit.textureCoord " +hit.textureCoord);
//print("hit.textureCoord2 " +hit.textureCoord2);
//print("hit.collider " +hit.collider);
//print("hit.rigidbody " +hit.rigidbody);
//print("hit.transform " +hit.transform);
//print("hit.barycentricCoordinate " +hit.barycentricCoordinate);
Any help is welcome
Thanks
I’m pretty sure hit.gameObject.renderer.material will get the material (yeah it’s fairly nested). hit.gameObject.renderer will return null if there is no renderer, so you should probably have an if statement to check that if you have gameObjects that you’ll check the material of but don’t have a material.
Thank Flashflow.
‘renderer’ is not a member of ‘UnityEngine.RaycastHit’
It’s doesn’t work I hope someone as the good answers
please try
hit.transform.renderer.material
What if the mesh has multiple materials? I have a golf course mesh that I’d like to keep all in one file but there are different materials for the green, the rough, the fairway, etc. I’d like to raycast against the mesh and know which material the triangle that was hit has. I haven’t found anything to suggest this is possible though.
Hello Ender13,
did you solved your problem?
Can you help me to retrieve material from triangle using raycast?
Any help is really appreciated!
Kenshin
I’m interested in this as well, any clues?