简体   繁体   中英

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. Problem is that the when the Button is pressed the whole background just turns grey as if the Background object just disappeared.

I figured it out myself and its a classic 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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