我正在编写一个点击器游戏,我不希望我的程序在我按下UI时进行计算。我试过使用!EventSystem.current.IsPointerOverGameObject(),OnPointerDown和OnMouseDown,但它们都破坏了点击的感觉,因为你不能垃圾点击。有没有更短的选择?提前谢谢你!
编辑:我已经做了你评论的所有事情,我找到了问题所在。每当我点击我的鼠标按钮时,文本就会出现,上面写着我每次点击得到的硬币数量。因此,它被算作UI元素,因此不可能进行垃圾邮件单击。我现在已经关闭了文本的“光线投射目标”,现在它可以正常工作了。谢谢你的帮助!
发布于 2020-12-31 20:47:50
您可以使用带有复选标记的输入类:
void Update()
{
// Check if the left mouse button was clicked
if (Input.GetMouseButtonDown(0))
{
// Check if the mouse was clicked over a UI element
if (EventSystem.current.IsPointerOverGameObject())
{
Debug.Log("Clicked on the UI");
}
}
}或者,您可以在想要检测点击的特定对象上使用OnMouseDown,但需要进行UI检查: void OnMouseDown() {
// Check if the mouse was clicked over a UI element
if (EventSystem.current.IsPointerOverGameObject())
{
Debug.Log("Clicked on the UI");
}
}https://stackoverflow.com/questions/65514115
复制相似问题