1 回答

TA貢獻1890條經驗 獲得超9個贊
請注意,這Dropdown.value
是 0 基索引,因此第一個條目0
不是1
. 我不知道您的完整設置,但我想這是您嘗試的主要問題。
然后 Dropdowns 有一個事件onValueChanged
而不是在Update
你應該注冊一個監聽器
private void Start()
{
// Just to be sure it is always only added once
// I have the habit to remove before adding a listener
// This is valid even if the listener was not added yet
myDropdown.onValueChanged.RemoveListener(HandleValueChanged);
myDropdown.onValueChanged.AddListener(HandleValueChanged);
}
private void OnDestroy()
{
// To avoid errors also remove listeners as soon as they
// are not needed anymore
// Otherwise in the case this object is destroyed but the dropdown is not
// it would still try to call your listener -> Exception
myDropdown.onValueChanged.RemoveListener(HandleValueChanged);
}
private void HandleValueChanged(int newValue)
{
switch (newValue)
{
case 0:
Debug.Log("Basic panel!");
modalPanelObject.SetActive(true);
modalPanelObjectAdvance.SetActive(false);
break;
case 1:
Debug.Log("Advance panel!");
modalPanelObjectAdvance.SetActive(true);
modalPanelObject.SetActive(false);
break;
}
}
提示:你可以使用通用的FindObjectOfType
modalPanel = FindObjectOfType<WithrowModalPanel>();
- 1 回答
- 0 關注
- 282 瀏覽
添加回答
舉報