C# IsPointerOverGameObject对于触摸始终返回false
IsPointerOverGameObject对于触摸始终返回C# IsPointerOverGameObject对于触摸始终返回false,c#,unity3d,C#,Unity3d,IsPointerOverGameObject对于触摸始终返回false。 我已经尝试了所有我能找到的解决办法 它在编辑器中工作得很好-通过UI阻止点击,但是没有一个移动设备,这个方法总是返回false 这是我的密码: private static bool IsPointerOverGameObject() { bool isPointerOverGameObject = EventSystem.current.IsPointerOverGameObject();
false
。
我已经尝试了所有我能找到的解决办法
它在编辑器中工作得很好-通过UI阻止点击,但是没有一个移动设备,这个方法总是返回false
这是我的密码:
private static bool IsPointerOverGameObject()
{
bool isPointerOverGameObject = EventSystem.current.IsPointerOverGameObject();
for (int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.touches[i];
if (touch.phase != TouchPhase.Canceled && touch.phase != TouchPhase.Ended)
{
if (EventSystem.current.IsPointerOverGameObject(Input.touches[i].fingerId))
{
isPointerOverGameObject = true;
break;
}
}
}
return isPointerOverGameObject;
}
public void OnMouseDown()
{
if (IsPointerOverGameObject())
{
return;
}
// code
}
private static bool IsPointerOverGameObject()
{
bool isPointerOverGameObject=EventSystem.current.isPointerOverGameObject();
对于(int i=0;i
根据unity的帮助论坛
EventSystem.current.IsPointerOverGameObject()
要求传递参数中的触摸id。尝试将其作为参数传递,以便在移动设备中使用,而对于编辑器,则需要将其保留为空
试试这个EventSystem.current.IsPointerOverGameObject(Input.touchs[i].fingerId)
编辑:我的错,我没有看到你已经在传递我看到的第一行代码中的触摸id,我认为它丢失了。根据unity的帮助论坛
EventSystem.current.IsPointerOverGameObject()
要求传递参数中的触摸id。尝试将其作为参数传递,以便在移动设备中使用,而对于编辑器,则需要将其保留为空
试试这个EventSystem.current.IsPointerOverGameObject(Input.touchs[i].fingerId)
编辑:我的错,我没有看到你在代码中已经传递了触摸id,我看到了第一行,并认为它丢失了。他是
EventSystem.current.IsPointerOverGameObject(Input.toucks[I].fingerId)
他是EventSystem.current.IsPointerOverGameObject(Input.touchs[I].fingerId)
根据文档,你需要它是触摸阶段。开始时
,你的检查允许触摸阶段。静止时
和触摸阶段。移动时
,我理解这会把它扔掉。根据文档,你需要它是触摸阶段。开始时
并且你的检查允许触摸阶段。静止时
和TouchPhase.Moved
,据我所知,这会使它消失。