简体   繁体   English

Unity 在运行时更改 UI 图像颜色

[英]Unity change UI Image color during Runtime

public void ChaGradient(int tid)
{
    go.GetComponent<RawImage>().color = color[tid];
}

I attached this script to a the Camera object and made it be called on a OnClick() Button event with the the goal to change the Background color depending on what Button is pressed.我将此脚本附加到相机 object 并在 OnClick() Button 事件上调用它,目的是根据按下的按钮更改背景颜色。 Problem is that the when the Button is pressed the whole background just turns grey as if the Background object just disappeared.问题是当按下按钮时,整个背景只是变成灰色,就好像背景 object 刚刚消失一样。

I figured it out myself and its a classic oopsie.我自己弄清楚了,它是一个经典的oopsie。 So when changing a color in the inspector it starts of with having an alpha of 0. So when you change the color on the color picker it does not change the alpha value, which is why it was invisible.因此,当在检查器中更改颜色时,它的 alpha 为 0。因此,当您在颜色选择器上更改颜色时,它不会更改 alpha 值,这就是它不可见的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM