Can't change GameObject color via script?

前端 未结 1 1765
北海茫月
北海茫月 2020-11-27 08:13

I have a canvas for UI, with an image the same size of the canvas. The Image has an rgba of 0,0,0,0 , making it invisible (because the

相关标签:
1条回答
  • 2020-11-27 09:02

    Here is your problem:

    new Color(0f, 0f, 0f, **255f**);

    The Color constructor parameter takes values from 0f to 1f but you are passing 0f to 255f range value to it.

    That should be:

    colorToFadeTo = new Color(0f, 0f, 0f, 1f);
    

    If you want to use the 0 to 255 range then you must divide it by 255.

    colorToFadeTo = new Color(0f, 0f, 0f, 255f/255f);
    

    Also, there is Color32 which can take values between 0 and 255. You can use that then covert it back to color.

    Color32 color32 = new Color32(0f, 0f, 0f, 255f));
    Color color = color32;
    
    0 讨论(0)
提交回复
热议问题