在新的 Unity 上设置 Alpha 通道 UI
Setting Alpha Channel on new Unity UI
我正在开发口渴系统。我想将图像的 Alpha 设置为 thirst number 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;
}
在 Unity3D 中,颜色需要一个从 0 到 1 的浮点值,所以我建议这样做:
temp.a = (currentThirst % 255) / 255.0f;
将 0 到 255 的期望值转换为 0 到 1 的浮点值。
希望这有帮助。
我正在开发口渴系统。我想将图像的 Alpha 设置为 thirst number 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;
}
在 Unity3D 中,颜色需要一个从 0 到 1 的浮点值,所以我建议这样做:
temp.a = (currentThirst % 255) / 255.0f;
将 0 到 255 的期望值转换为 0 到 1 的浮点值。 希望这有帮助。