Unity3D材质未显示,但已正确设置 [英] Unity3D materials not displaying, but being set correctly

查看:1556
本文介绍了Unity3D材质未显示,但已正确设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态加载对象,并根据从某人计算机上文件中获取的每个子对象的状态为每个子对象着色.

I am trying to dynamically load an object, and color each sub-object based on the state of it taken from a file on someone's computer.

可以很好地加载对象,并且已经设置了材质,但是在游戏运行时,这种着色在场景中不起作用.我这样做是这样的:

Loading the object is fine, and the material is being set, but this coloring is not working in the scene while the game is running. I am doing this like this:

grandchild.GetComponent<Renderer>().material.EnableKeyword("_NORMALMAP");

grandchild.GetComponent<Renderer>().material.SetColor("_Color", Color.yellow);

查看场景时,此颜色不可见(对象颜色与其原始颜色相同. 然后,我决定尝试将材料本身更改为如下所示的有色材料:

When viewing the scene, this color is not visible (the object color is the same as its original color. I then decided to try changing the material itself to a colored one like this:

grandchild.GetComponent<Renderer>().material = (Material)Resources.Load("YellowMaterial", typeof(Material);

这也不起作用,正在设置材质(进入场景编辑器并查看对象属性显示了正确的材质),但是对象没有改变颜色,而是保留了默认设置.但是,在素材资源文件夹中获取材质并在场景编辑器中将其手动拖动到对象中是可以的.我不确定自己在做什么错,因此我们将不胜感激!

This did not work either, the material is being set (going into the scene editor and viewing the object properties shows the correct material), but the object is not changing color and instead keeps it's default. However, taking a material in the assets folder and manually dragging it to the object in the scene editor does work. I'm not sure what I'm doing wrong here, so any help would be greatly appreciated!

这是我在说些什么的图片

Here are some pictures of what I'm talking about

检查器中的对象(材料更改后):

The object in the inspector (After material change):

场景中的对象:

材料属性:

推荐答案

GarrotJohnson和derHugo让我知道了问题所在.事实证明,我正在使用的每个对象都有一个子对象(由于某种原因称为默认"),该子对象具有自己的Mesh Renderer和默认材质.获取此子对象(GameObject.transform.GetChild(0))并更改该材质即可.

GarrotJohnson and derHugo gave me an idea of what the problem could be. It turns out, each of the objects I was working with had a child object (called "default" for some reason), which has its own Mesh Renderer and default material. Getting this child object (GameObject.transform.GetChild(0)) and changing that material works.

这篇关于Unity3D材质未显示,但已正确设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆