- Home /
How to get Texture Name from textureCoord or RaycastHit in a Mesh with multiple materials?
Hi,
I send a Physics.Raycast (ray, out hit, range) that hits an GameObject. The GameObject have a Mesh Collider, and a Mesh with 6 different materials (6 textures). I need to change the effect I spawn based on the Texture at the hit point.
How can I get the Texture at the hit point (hit)?
I now I can get the Textures coordinates via hit.textureCoord, and that hit.collider.renderer.material.mainTexture returns only the first out of the six textures. As textureCoord return the UV point, I was wondering a way to get the Texture name from the UV coordinates, but I couldn't find a way yet.
If you have 6 materials in the same mesh, all of them are rendered, thus what you see is only the last material rendered (unless they have transparent parts). You can only show all materials when they are assigned to different submeshes - do you have submeshes in this object?