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 关注
- 213 浏览
添加回答
举报