我有此代码,当我单击按钮时,将打开一个面板。在同一脚本中,我具有 Update()函数,该函数检查是否在按钮/面板外部单击,以便它可以关闭所有打开的面板。问题是,当我单击按钮以关闭面板时,面板会快速关闭并重新打开。
这是到目前为止我正在使用的代码。如果有任何疑问或更多信息,请随时提出。
谢谢!
public void Update()
{
if (Input.GetMouseButton(0) && panel.activeSelf && !RectTransformUtility.RectangleContainsScreenPoint(panel.GetComponent<RectTransform>(),
Input.mousePosition, Camera.main))
panel.SetActive(false);
}
public void abrir_painel()
{
if (panel != null)
panel.SetActive(!panel.activeSelf);
}