我在运行时通过脚本创建了一组预制件。它们保存在一个名为 newObj 的数组中。每个都有一些文本 UI 和一些按钮,我使用 GetComponentsInChildren 检索它们。当用户单击预制件中的第一个按钮时,我想运行一个更改按钮文本并突出显示该按钮的函数。
一切正常,除了按钮没有突出显示。
public void SelectPlayer(int rowSelected)
{
var buttons = newObj[rowSelected].GetComponentsInChildren<Button>();
var texts = newObj[rowSelected].GetComponentsInChildren<Text>();
texts[0].text = "1";
buttons[0].Select();
buttons[0].OnDeselect(null);
}