unity, access material

Unity中MeshRenderer与Material的使用与操作

 

          MeshRenderer meshRenderer=gameObject.GetComponent<MeshRenderer>();
                if(meshRenderer!=null){
                    Material material=meshRenderer.material;
                    if(material!=null){
                        do something with material
                    }
                }

参考:

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 will change the material for this object only.

If the material is used by any other renderers, this will 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 is usually only called when loading a new level.

 

 

 

转载于:https://www.cnblogs.com/wantnon/p/4525291.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值