Unity, Access material

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.