Unity Button.Image.Color赢得';";刷新“;

Unity Button.Image.Color赢得';";刷新“;,image,unity3d,button,colors,rgb,Image,Unity3d,Button,Colors,Rgb,今天早上我的Button.Image.Color出现问题 下面是我真正简单的代码: this.gameObject.GetComponent<Image>().color = Color.Red; this.gameObject.GetComponent().color=color.Red; 所以这一行非常好用…现在,我正试图用我自己的颜色,用这一行简单的代码: this.gameObject.GetComponent<Image>().color = new Col

今天早上我的Button.Image.Color出现问题

下面是我真正简单的代码:

this.gameObject.GetComponent<Image>().color = Color.Red;
this.gameObject.GetComponent().color=color.Red;
所以这一行非常好用…现在,我正试图用我自己的颜色,用这一行简单的代码:

this.gameObject.GetComponent<Image>().color = new Color(106, 174, 23);
this.gameObject.GetComponent().color=新颜色(10617423);
嗯,颜色实际上会改变…但不会改变…让我们在游戏运行时参考对象本身:

如你所见,颜色改变了,但它保持白色


我在这里看过很多帖子,但是看起来我做得很好,很明显这是一个错误,否则它会工作得很好,但即使在阅读了很多帖子之后,似乎我自己也看不到解决方案。

Color接受0-1的浮动作为它的构造函数

您正在将它们设置为1(高于1的任何项都设置为1)。和1,1,1=白色

this.gameObject.GetComponent<Image>().color = new Color(0.415f, 0.682f, 0.09f);
this.gameObject.GetComponent().color=新颜色(0.415f、0.682f、0.09f);
这会给你你想要的结果

这些数字是通过将值除以255生成的

或者,您也可以解析您的hexvalue:

if(Color.TryParseHtmlString("#75BF1A", out myColor))
{
    this.gameObject.GetComponent<Image>().color = myColor;
}
if(Color.TryParseHtmlString(#75BF1A),out myColor))
{
this.gameObject.GetComponent().color=myColor;
}

Color为其构造函数接受范围从0到1的浮动

您正在将它们设置为1(高于1的任何项都设置为1)。和1,1,1=白色

this.gameObject.GetComponent<Image>().color = new Color(0.415f, 0.682f, 0.09f);
this.gameObject.GetComponent().color=新颜色(0.415f、0.682f、0.09f);
这会给你你想要的结果

这些数字是通过将值除以255生成的

或者,您也可以解析您的hexvalue:

if(Color.TryParseHtmlString("#75BF1A", out myColor))
{
    this.gameObject.GetComponent<Image>().color = myColor;
}
if(Color.TryParseHtmlString(#75BF1A),out myColor))
{
this.gameObject.GetComponent().color=myColor;
}

您好,谢谢您的回答,颜色确实需要从0到1的数字

为了补充您的答案,我发现Color32是我应该使用的颜色,因为它接受0-255的值


再次感谢,祝你度过愉快的一天

您好,谢谢您的回答,颜色确实需要从0到1的数字

为了补充您的答案,我发现Color32是我应该使用的颜色,因为它接受0-255的值

再次感谢,祝你度过愉快的一天