在新的Unity UI上设置Alpha通道

时间:2015-02-22 01:17:59

标签: c# user-interface unity3d

我正在研究解渴系统。我想将图像的Alpha设置为口号mod 255以将其设置为接近255的数字,因此它在alpha的255范围内。为什么我不能将Alpha设置为该数字。我已经过测试,如果我这样做了 - =而且我选择了一个数字,它会下降。任何解决方案?

这是我的代码

void Update() {
    currentThirst -= Time.deltaTime / 2;
    currentHunger -= Time.deltaTime / 2;

    Color temp = thirstImage.color;
    temp.a = (currentThirst % 255);
    thirstImage.color = temp;
}

1 个答案:

答案 0 :(得分:1)

Unity3D中的颜色要求浮点值从0到1,所以我建议做类似的事情:

temp.a = (currentThirst % 255) / 255.0f;

将0到255的期望值转换为0到1的浮点值。 希望这会有所帮助。

相关问题