c# - 考虑将值存储在临时变量 (UI.graphic.color)
问题描述
我正在尝试更改多个 UI 元素的 alpha。
“UnityEngine.UI.Graphic.color 考虑将值存储在临时变量中”
public class DialogueManager : MonoBehaviour {
public Text nameText;
public Text dialogueText;
public Image facePlate;
public PlayerController thePlayer;
void Awake () {
thePlayer = FindObjectOfType<PlayerController> ();
}
void Update () {
if (!thePlayer.isTalking) {
Color temp = facePlate.color;
temp.a = 0f;
nameText.color.a = temp.a;
dialogueText.color.a = temp.a;
facePlate.color.a = temp.a;
}
我尝试了多种方法来做到这一点,尽管我总是以同样的错误告终。
解决方案
您不能直接更改 Color 的任何变量。因此,您可以将 Color 结构的值分配给临时变量并更改它。然后将温度重新分配给颜色部分。在这里,我们每次基本上都是取颜色变量的值并修改它并重新分配新值
if (!thePlayer.isTalking) {
Color temp = facePlate.color;
temp.a = 0f;
facePlate.color = temp;
temp = nameText.color;
temp.a = 0f;
nameText.color = temp;
temp = dialogueText.color;
temp.a = 0f;
dialogueText.color = temp;
}
推荐阅读
- javascript - 安全问题:在 POST 请求中发送访问令牌
- reactjs - 我正在尝试使用 jest 在我的代码中执行单元测试,但出现错误
- java - 如何更改同步适配器项目名称
- java - 快速将新创建的对象添加到数组中
- swift - 具有依赖注入的类与具有实现的协议
- sql - 在sql中查找并显示
- ruby-on-rails - 枚举和包含在 models.rb 中不获取数据
- php - imageMagick gif 移出框架
- mongodb - 如何使用java mongo spark连接器进行upsert操作并处理spark中的数据?
- javascript - 以不同的方式声明方法