C# 变量在赋值后未更改,更改显示在 UI 中

C# Variable not changing after Assignment, Change shows in UI

在我的记分牌 UI 中,我有一个框,它只是一个图像,里面有 Score_Entries 作为 children。有 4 个 children,游戏中每个玩家一个。当记分牌启动时,我有一个函数可以分配 Score_Entries Ui 元素内的文本。为此,我有一个名为 Text[] playerNames 的数组,我的 UI 元素在检查器中被拖入其中。

int i = 0;
foreach (Player test in PhotonNetwork.PlayerList)
{
    playerNames[i].text = test.NickName;
    allscores[i].text = 0.ToString();
    i++;
    Debug.Log("Text inside the array: " + playerNames[i].text);
    Debug.Log("Player Name: " + test.NickName);
}

如您所见,我已将第一个 Text 元素中的文本设置为玩家的名字。然而,应该发生的是在 Debug 语句中播放器名称行输出和数组输出中的文本应该显示存储在 test.NickName 中的字符串。说测试是玩家的名字。 playersNames[i].text should == test 当前它显示 playerNames[i] = TEST NAME 这是我创建 UI 时的默认文本。但是,在游戏中,玩家的名字正确显示为 test 而不是 TEST NAME。

我不明白这是怎么回事有人可以帮忙吗?

问题是i++ 将 i++ 放在

之后
Debug.Log("Text inside the array: " + playerNames[i].text);
Debug.Log("Player Name: " + test.NickName);
i++