Forum rules - please read before posting.

Unity UI blocks interaction and movement on mobile

Hello

There was a topic started by me https://www.adventurecreator.org/forum/discussion/8980/clicking-on-gui-causes-player-move-to-that-point#latest

Your fix works for PC but doesn't work for mobile (touchscreen). Is there a way to fix it?

Comments

  • edited October 2019

    Let me know if this replacement for the PlayerInteraction.cs script's UnityUIBlocksClicks function does the trick:

    protected virtual bool UnityUIBlocksClick ()
    {
        if (KickStarter.settingsManager.unityUIClicksAlwaysBlocks)
        {
            if (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver)
            {
                if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject ())
                {
                    return true;
                }
    
                if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    
  • You code brings up an error. Here is a little bit edited one:

    protected virtual bool UnityUIBlocksClick ()
    {
        if (KickStarter.settingsManager.unityUIClicksAlwaysBlocks)
        {
            if (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver)
            {
                if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject ())
                {
                    return true;
                }
    
                if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    

    Bit it doesn’t help anyway. We tried on emulator and tap still makes player move to that point

  • Though it's likely not going to make a difference, the EventSystem call should be consistent:

    if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
    {
        return true;
    }
    

    It should be something along those lines. I'll experiment some more.

  • Ah. That code is correct, but is only dealing with interactions. Movement is a separate function. Same name, in PlayerMovement. Set this to:

    protected bool UnityUIBlocksClick ()
    {
        if (KickStarter.settingsManager.unityUIClicksAlwaysBlocks)
        {
            if (KickStarter.settingsManager.hotspotDetection == HotspotDetection.MouseOver)
            {
                if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject ())
                {
                    return true;
                }
    
                if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                {
                    if (KickStarter.playerMenus.EventSystem.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
    
  • Code works. Thank you. We’ve tested it on emulator.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.