Hi Playmakers,
I'm creating some custom actions for a project that I'm working on and I need to determine if a touch input (touch began) hits a UI element or not. I found out that this works with "IsPointerOverGameObject" and wrote a custom action which you can see here:
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using System;
using UnityEngine;
using UnityEngine.EventSystems;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Device)]
[Tooltip("Sends an Event if an Object gets touched and another Event if the UI gets touched.")]
public class TouchEventPF : FsmStateAction
{
[ActionSection("Events")]
[Tooltip("Event to send on touch began.")]
public FsmEvent touchObject;
[Tooltip("Event to send on canvas touch.")]
public FsmEvent touchCanvas;
[ActionSection("Store Results")]
[UIHint(UIHint.Variable)]
[Tooltip("Store the fingerId of the touch.")]
public FsmInt storeFingerId;
private UnityEngine.EventSystems.EventSystem _eventSystem;
public override void Reset()
{
touchObject = null;
touchCanvas = null;
storeFingerId = null;
}
public override void OnEnter ()
{
_eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
Debug.Log (_eventSystem);
}
public override void OnUpdate()
{
if (Input.touchCount > 0)
{
foreach (var touch in Input.touches)
{
storeFingerId.Value = touch.fingerId;
if (_eventSystem.IsPointerOverGameObject())
{
Fsm.Event(touchCanvas);
Debug.Log ("Touch Canvas!");
}
else
{
Fsm.Event(touchObject);
}
}
}
}
}
}
This works well with Unity Remote (Android) but it doesn't work on the device after building and running the app and the touch goes right trough the UI.
After some research on the web I found this solution for the problem:
http://gamedev.stackexchange.com/questions/90196/how-to-detect-that-user-has-touched-ui-canvas-in-unity-4-6Obviously the problem is that "On Mobile you need to need pass Touch.fingerId as parameter into EventSystem.IsPointerOverGameObject(int pointerID)" as stated in this forum post.
Sounds logical but I can't get it to work if I change my code from
if (_eventSystem.IsPointerOverGameObject())
to
if (_eventSystem.IsPointerOverGameObject(
touch.fingerId))
With the change it doesn't work in any environment: not in the unity remote and not on the device itself :-(
Can you please help me? This drives me crazy and I need it to continue the work on my project

Thanks and best regards,
polygon