在 Unity 中更改游戏对象的颜色 [英] Changing color of of gameObject in Unity

查看:73
本文介绍了在 Unity 中更改游戏对象的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有这个代码.

void Start () {
    gameObject.GetComponent<Renderer> ().material.color = Color.green;
}

我希望我的游戏对象将其颜色更改为绿色.我将它导入为黑色,在检查器中它变成了绿色,但在实际应用程序中它没有显示为绿色.我不能使用 gameObject.renderer.material.color = Color.green 因为统一告诉我它基本上已经过时了,我必须使用新版本.这将非常简单,但我错过了什么?提前致谢.

I expected my gameObject to change its color to green. I imported it as black and in the inspector it has turned to green however in the actual application it does not appear as green. I cant use gameObject.renderer.material.color = Color.green since unity tell me its basically outdated and that I have to use the new version. This is going to be really simple but what am I missing? Thanks in advance.

更新:当我运行代码时,会在检查器Sprites-Default(实例)"中弹出一个选项卡,如果我将选择框更改为 Unlit > Color,它就可以工作了.有没有办法制作这个棒子?

UPDATE: When I run the code a tab pops up in the inspector 'Sprites-Default (instance)' and if I change the selection box to Unlit > Color it works. Is there anyway of making this stick?

推荐答案

颜色改变了,但你看不到结果,因为材质中的着色器需要光,而你没有光,所以你总是看到它是黑色的,所以你可以添加光源或将材质着色器更改为不亮.

the color changes but you cant see the result because the shader in your material needs light and you don't have lights so you will always see it black so you can add a light source or change the materials shader to unlight.

这篇关于在 Unity 中更改游戏对象的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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