如何通过UI元素检测点击?我做了一个画布,在画布上有一个可拖动/滚动的面板,当你按下游戏对象时,它会自动打开,如果我按下游戏对象以外的任何地方,它会自动关闭。问题是,每当我试图在手指没有悬停在游戏对象上的地方滚动时,即使我试图在面板区域滚动,窗口也会关闭
I am using Raycast to detect a gameobject with a layermask and found another method which is places inside of if statement which check for clicks. Here's my code for panel animation of the up-down movement:
if (Input.GetMouseButtonDown(0))
{
//to prevent indicator to be clicked when using UI elements.
//It is put after checking for button click and before creating Ray
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Boutiques"))
{
GetComponent<Animator>().Play("AnimUP");
}
}
else {GetComponent<Animator>().Play("AnimDOWN");
}
}
我试图做一个可滚动的窗口,当你用手指按一个物体时,它会打开,如果你按窗口外的某个地方,衣服会放下
1条答案
按热度按时间ncecgwcz1#
您可以在Update.查找示例脚本中检查touchPhase: