unity里怎么用代码更换材质球的颜色,求具体的步骤

unity里怎么用代码更换材质球的颜色,求具体的步骤,第1张

新建一个c#文件,名称为Test,复制以下代码到文件里,然后拖到要变色的物体上,运行,OK
using SystemCollections;
using SystemCollectionsGeneric;
using UnityEngine;
public class Test : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
GetComponent<Renderer>()materialcolor = Colorred;
DebugLog("我变红啦!");
}
}

mycuberenderermaterialcolor = Colorred;//这是把mycube这个物体设置为红色
要改其它颜色,定义一个颜色值就行,比如 = new Color(01f,02f,03f,10f),注意最后一个值是alfa,就是影响透明度的,设为1就是不透明,要表现出半透明就是05,前提是这个shader要支持透明通道


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/13350037.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-07-19
下一篇 2023-07-19

发表评论

登录后才能评论

评论列表(0条)

保存