考虑将值存储在临时变量中 (UI.graphic.color)

Considering storing the value in a temporary variable (UI.graphic.color)

我正在尝试更改多个 UI 元素的 alpha。

"UnityEngine.UI.Graphic.color Considering storing the value in a temporary variable"

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的any变量。因此,您可以将 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;
}