博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
unity, access material
阅读量:4662 次
发布时间:2019-06-09

本文共 973 字,大约阅读时间需要 3 分钟。

 

          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

你可能感兴趣的文章
【bzoj1712】[Usaco2007 China]Summing Sums 加密 矩阵乘法
查看>>
如何解决git创建密匙时报错Too many arguments
查看>>
python学习笔记-25 实例属性和类属性
查看>>
python 单例模式
查看>>
Java知识积累——String引用的判断问题
查看>>
Asp.Net Web API 2第七课——Web API异常处理
查看>>
bzoj 2339: [HNOI2011]卡农
查看>>
[Canvas]新版箴言钟表
查看>>
杭电(hdu)2053 Switch Game 水题
查看>>
SDUT -refresh的停车场(栈和队列)
查看>>
使用Charles请求跳转可作为线上和线下环境的切换
查看>>
跨域请求
查看>>
浅谈Java反射
查看>>
cocos2d-x 3.8 lua 关于setAnimationCompletedCallback的修改
查看>>
BZOJ 2037 区间DP
查看>>
hihocoder1415 重复旋律3
查看>>
STL-queue和循环队列基本操作的实现
查看>>
Python 字符串常用方法
查看>>
ant中build.xml文件解释
查看>>
自动化测试
查看>>