- Home /
access material that is linked to face
Hi!
I wanted to ask this to see if it was possible!
Is it possible to get the material that is displayed on a face?
For example, I have a mesh with two materials. If I 'shoot' the mesh, can I see what material was assigned to that face?
Thanks,
-Aj
Answer by efge · Apr 11, 2011 at 10:48 AM
If 'shoot' the mesh means colliding with the mesh (detected by OnCollisionEnter or a Physics.Raycast) you can access the component(s) like this:
Graphics material used by the renderer:
collider.renderer.material
The Physics material is also available:
collider.material
Will this just default to the first material in the Renderers materials list?
Thanks for the response
-Aj
AJ did you ever get this to work. I'm trying to cast a ray against an object and return the material that is under the hitpoint. I can get the list of materials associated with the collider and of course the main/first material in the objects material list but not the material under the hitpoint.
I've been researching this recently, and found this page: http://forum.unity3d.com/threads/40377-Detecting-material-(material-index)-and-raycast-hit All you need to do to adapt this is use the hitSub$$anonymous$$eshNumber variable to get the index of the material on the hit object
Hope this is what you are looking for!
-AJ
That worked perfectly! Thanks for the heads up, saved us some time in having to split up all of our multiple material objects into separate objects.