Renderer.material

public Material material;

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.

 
解释:该方法会返回第一个(有多个实例材质的情况下),修改材质的化只会修改这个物体的材质颜色,如果该材质有共享体,则会一起改变;
下面给的注意是:这个函数会自动实例化唯一的材质而且,当物体被销毁,则该材质也会被销毁,除非他在新的一层被联系。
 
我的代码实例:

void OnMouseEnter()
{
if(turretGo==null&&EventSystem.current.IsPointerOverGameObject())
{
renderer.material.color = Color.red;
}
}
void OnMouseExit()
{
renderer.material.color = Color.white;
}

//该代码实现当物体放在一个物体上显示红色,离开显示白色

官方代码实例:

using UnityEngine;
using System.Collections; // Change renderer's material each changeInterval
// seconds from the material array defined in the inspector.
public class ExampleClass : MonoBehaviour
{
public Material[] materials;
public float changeInterval = 0.33F;
public Renderer rend; void Start()
{
rend = GetComponent<Renderer>();
rend.enabled = true;
} void Update()
{
if (materials.Length == 0)
return; // we want this material index now
int index = Mathf.FloorToInt(Time.time / changeInterval); // take a modulo with materials count so that animation repeats
index = index % materials.Length; // assign it to the renderer
rend.sharedMaterial = materials[index];
}
}

uintAPi 之Renderer.material的更多相关文章

  1. Renderer.materials

    修改方法 meshBody.renderer.materials[].mainTexture= clothes[]; meshBody.renderer.materials[]=maters[]; 以 ...

  2. Material

    renderer.material  物理材质 实现二维图上的人物动作 新建Material,选择Shader(著色器)为transparent/diffuse(背景透明),将上图拉到背景图选项中. ...

  3. Unity修改Particles Render Material(Unity3D开发之二十三)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/48372999 ...

  4. unity3D中 material中tiling和offset属性解释

    贴图有可能是多行多列的一些图案组成的.当我们需要一帧,一帧的播放时候.也就是帧序列动画, 我们就需要用到tiling和offset两个属性, 默认图片的左下角为坐标圆点即:(0,0) tiling是图 ...

  5. unity, access material

    MeshRenderer meshRenderer=gameObject.GetComponent<MeshRenderer>();                if(meshRende ...

  6. 【Unity3D】Unity3D中Material与ShareMaterial引用的区别

    我们在使用Unity引擎的时候,有时候需要去修改某个物体上的Material,在Unity的Renderer类里,提供了两个方法接口供我们使用. Renderer.material和Renderer. ...

  7. 深入浅出聊优化:从Draw Calls到GC

    前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...

  8. 匹夫细说C#:庖丁解牛聊委托,那些编译器藏的和U3D给的

    0x00 前言 由于工作繁忙所以距离上一篇博客已经过去一个多月的时间了,因此决心这个周末无论如何也得写点东西出来,既是总结也是分享.那么本文主要的内容集中在了委托的使用以及内部结构(当然还有事件了,但 ...

  9. Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译

    本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...

随机推荐

  1. redis设置密码

    1.初始化Redis密码: 在redis.conf配置文件中有个参数: requirepass  这个就是配置redis访问密码的参数: 比如 requirepass test123: (Ps:需重启 ...

  2. VS2010 LNK1123: 转换到 COFF 期间失败: 文件无效或损坏

    1嵌入清单问题 属性: 项目\属性\配置属性\清单工具\输入和输出\嵌入清单:原来是“是”,改成“否”. 项目\属性\配置属性\链接器\清单文件\生成清单:原来是“是”,改成“否”. 2文件老旧: c ...

  3. java 中拿项目路径

    public class ItemPathInterceptor extends HandlerInterceptorAdapter { @Override public boolean preHan ...

  4. css动画特效

    <html> <head> <meta charset="utf-8" /> <title>6种css3鼠标滑过动画效果</t ...

  5. rancher的Ingress的文件大小上传限制配置

    添加注释 nginx.ingress.kubernetes.io/proxy-body-size

  6. VS2015一新建项目就出现未将对象引用设置到对象的实例怎么办?[z]

    https://blog.csdn.net/tiandyoin/article/details/79722800 在控制面板-卸载或修复程序太麻烦,而且不一定保证解决,可以这样------打开--C: ...

  7. Redis master/slave,sentinel,Cluster简单总结

    现在互联网项目中大量使用了redis,本文著主要分析下redis 单点,master/slave,sentinel模式.cluster的一些特点. 一.单节点模式 单节点实例还是比较简单的,平时做个测 ...

  8. 获取txt md5值上传文件完整性校验

    网络上传文件到服务器 做md5 校对.判断文件是否破坏 首先求txt文件的md5值 ,1万条数据 求出的值 文件MD5:e5467b6a8e3c26af8c5af0bda3739280 服务器处理程序 ...

  9. centos7 删除swap

    https://www.refmanual.com/2016/01/08/completely-remove-swap-on-ce7/#.W8AaSRMzaRs 删除不干净,启动不起来的情况下.需要从 ...

  10. 使用jconsole分析内存情况-JVM

    JVM调优分析演练: Jconsole中对内存为如下结构: 原始代码: public static void main(String[] args) { BigInteger [] pArr=new ...