列表遍历运用
List<Transform> MainMenuBtn = new List<Transform>();
//遍历所有按钮,并重置按钮状态
private void RestButtonInteractive(Transform btn)
{
foreach (Transform kk in MainMenuBtn)
{
if (kk == btn)
{
kk.GetComponent<Button>().interactable = false;
}
else
{
kk.GetComponent<Button>().interactable = true;
}
}
}
//查找遍历所有按钮,并添加到列表中
private void StroeMainMenuBtnData()
{
var btn = mainLogo.transform.FindChild("back/menuPanel");
foreach (Transform kk in btn.transform)
{
if (kk.GetComponent<Button>() != null)
{
MainMenuBtn.Add(kk);
}
}
}