uintAPi 之Renderer.material
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的更多相关文章
- Renderer.materials
修改方法 meshBody.renderer.materials[].mainTexture= clothes[]; meshBody.renderer.materials[]=maters[]; 以 ...
- Material
renderer.material 物理材质 实现二维图上的人物动作 新建Material,选择Shader(著色器)为transparent/diffuse(背景透明),将上图拉到背景图选项中. ...
- Unity修改Particles Render Material(Unity3D开发之二十三)
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/48372999 ...
- unity3D中 material中tiling和offset属性解释
贴图有可能是多行多列的一些图案组成的.当我们需要一帧,一帧的播放时候.也就是帧序列动画, 我们就需要用到tiling和offset两个属性, 默认图片的左下角为坐标圆点即:(0,0) tiling是图 ...
- unity, access material
MeshRenderer meshRenderer=gameObject.GetComponent<MeshRenderer>(); if(meshRende ...
- 【Unity3D】Unity3D中Material与ShareMaterial引用的区别
我们在使用Unity引擎的时候,有时候需要去修改某个物体上的Material,在Unity的Renderer类里,提供了两个方法接口供我们使用. Renderer.material和Renderer. ...
- 深入浅出聊优化:从Draw Calls到GC
前言: 刚开始写这篇文章的时候选了一个很土的题目...<Unity3D优化全解析>.因为这是一篇临时起意才写的文章,而且陈述的都是既有的事实,因而给自己“文(dou)学(bi)”加工留下的 ...
- 匹夫细说C#:庖丁解牛聊委托,那些编译器藏的和U3D给的
0x00 前言 由于工作繁忙所以距离上一篇博客已经过去一个多月的时间了,因此决心这个周末无论如何也得写点东西出来,既是总结也是分享.那么本文主要的内容集中在了委托的使用以及内部结构(当然还有事件了,但 ...
- Unity性能优化(4)-官方教程Optimizing graphics rendering in Unity games翻译
本文是Unity官方教程,性能优化系列的第四篇<Optimizing graphics rendering in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
随机推荐
- WEB-INF目录下的jsp怎么引用外部文件:js,css等
在项目中,为了安全.我们通常会将jsp文件放在WEB-INF下面,对于放在WEB-INF下面的js或是css等资源文件.我们通常可以通过相对路径来引用,而如果是放在WEB-INF之外的js 或是 cs ...
- pom.xml文件释义
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- wpf 给listview的数据源转换为集合
目的是点击某个按钮把一条数据从 itemssource中移除 private void delete_Click_1(object sender, RoutedEventArgs e) { DtsIn ...
- 对palindrome的常用判断
判断String是否为palindrome:Two Pointers(left & right) 同时边扫边check 当前两边的char是否相同 code public boolean is ...
- Java多线程02(线程安全、线程同步、等待唤醒机制)
Java多线程2(线程安全.线程同步.等待唤醒机制.单例设计模式) 1.线程安全 如果有多个线程在同时运行,而这些线程可能会同时运行这段代码.程序每次运行结果和单线程运行的结果是一样的,而且其他的变量 ...
- 《Java从入门到精通》学习总结1
1. Java既是编译型语音,也是解释型语言:先将源代码编译成Java字节码,然后Java虚拟机对Java字节码进行解释运行 2. 使用命令行编译Java源代码时,如果代码中有中文,在编译时需要指定编 ...
- centos7 端口3306无法连接问题
MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost,那么这个用户就只能本机访问,其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问. G ...
- chrome小书签-实用的小功能-javascript代码段
1.打印页面的所有脚本引用文件及代码段: javascript:var scriptarray=document.getElementsByTagName("script");fo ...
- JS 变量提升与函数提升
JS 变量提升与函数提升 JS变量提升 变量提升是指:使用var声明变量时,JS会将变量提升到所处作用域的顶部.举个简单的例子: 示例1 console.log(foo); // undefined ...
- 【java】:多线程面试题
经常面试的时候,让写各种乱七八糟的多线程面试题,收集了很多,有些还是挺好玩的. 1.编写程序实现,子线程循环10次,接着主线程循环20次,接着再子线程循环10次,主线程循环20次,如此反复,循环50次 ...