【发布时间】:2020-02-25 16:19:58
【问题描述】:
在我的 Unity 项目中,我尝试使用一些自制材料突出显示某些对象。 不幸的是,我找到的代码不起作用。
以下脚本被添加到三个不同的游戏对象中:
Renderer[] rend_ThisObject;
Material white, red;
void Start()
{
// I tried the following two code parts:
white = Resources.Load<Material>("White");
white = Resources.Load("Material/White.mat", typeof(Material)) as Material;
red = Resources.Load<Material>("Red");
red = Resources.Load("Material/Red.mat", typeof(Material)) as Material;
}
void Update()
{
foreach (var child in rend_ThisObject)
{
child.material = blinkObject ? white : red;
}
}
如果我运行该项目,带有脚本的游戏对象会显示为粉红色并且不会闪烁。
如果我将 Material white, red; 更改为 public Material white, red; 它工作正常。我必须更改哪些内容才能从我的 assets/resources/material 文件夹中获取材料?
【问题讨论】: