Meshrenderer meshrenderer=gameobject.getcomponent<meshrenderer> ();
if (meshrenderer!=null) {
Material material=meshrenderer.material;
if (material!=null) {
Do something with material
}
}
Reference:
1,http://forum.unity3d.com/threads/is-it-necessary-to-destroy-the-instance-material-manaully-in-unity-3-5.146946/
2, Renderer.material
Public Material Material;
Description
Returns the first instantiated Material assigned to the renderer.
Modifying material would change the material to this object only.
If the material is used by any other renderers, this would clone the shared material and start using it from now on.
Note:
This function automatically instantiates the materials and makes them unique to this renderer. It is your responsibility to destroy the materials when the game object is being destroyed. Resources.unloadunusedassets also destroys the materials but it's usually only called when loading a new level.
Unity, Access material