Forum rules - please read before posting.

Hotspot Use:interact on mouse/touch release

Hi there,
is there an easy way to override how the hotspot interactions are triggered? I would like them to run on mouse release instead of pressed.
I tried to have a look at the Custom Interaction System Example script but I'm a bit lost, and honestly not sure it could do what I need.
Any help? Thanks in advance.

Comments

  • edited March 2022

    When it comes to touch-screens, if your Input method is set to Touch Screen, then the Release touch to interact with scene? (Experimental) option should achieve this.

    Otherwise, though, you can rely on a custom script that overrides input - you don't need to override the interaction system.

    See the Manual's "Remapping inputs" chapter for details, but it essentially involves writing your own equivalents to Unity's Input.GetButtonDown etc functions that AC relies on as an alternative. Here's an example that registers "Mouse Up" events instead of "Mouse Down" when over a Hotspot:

    using UnityEngine;
    using AC;
    
    public class MouseDownOverride : MonoBehaviour
    {
    
        void Start ()
        {
            KickStarter.playerInput.InputGetMouseButtonDownDelegate = My_GetMouseButtonDown;
        }
    
        private bool My_GetMouseButtonDown (int button)
        {
            if (button == 0 && KickStarter.playerInteraction.IsMouseOverHotspot ())
            {
                return Input.GetButtonUp (0);
            }
            return Input.GetButtonDown (button);
        }
    
    }
    
  • edited March 2022

    Thank you Chris.
    I may be dumb but I looked everywhere and cannot find the the Release touch to interact with scene? (Experimental) option. I guess I am running the most recent AC version (1.75.1) and Input method is set Touch Screen. Can you please tell me in which tab it is?

    Also, I tried your script and I got 2 errors error CS1503: Argument 1: cannot convert from 'int' to 'string' so I changed it into:
    using UnityEngine;
    using AC;

    public class MouseDownOverride : MonoBehaviour
    {
    
        void Start ()
        {
            KickStarter.playerInput.InputGetMouseButtonDownDelegate = My_GetMouseButtonDown;
        }
    
        private bool My_GetMouseButtonDown (int button)
        {
            if (button == 0 && KickStarter.playerInteraction.IsMouseOverHotspot ())
            {
                return Input.GetMouseButtonUp(0);
            }
            return Input.GetMouseButtonDown(button);
        }
    
    }
    

    but now mousePressed is not recognized as it is supposed to do, but nothing happens at mouse release too. Had a look at the scripting guide and actually Input.GetMouseButtonUp doesn't seem to even exists but Input.GetButtonUp returns the cannot convert int to string error and it seems to be for keyboard buttons and not mouse.
    Any help? Thanks

  • I may be dumb but I looked everywhere and cannot find the the Release touch to interact with scene? (Experimental) option

    Sorry, I forgot to include that a requirement for this to show is that Moving touch drags cursor? must also be checked, and that the Movement method is not set to First Person.

    Also, I tried your script and I got 2 errors

    Quite right - apologies again, I was mixing up my approaches.

    Input.GetMouseButtonUp is a Unity function - it won't be in AC's Scripting Guide. However, it's also necessary to override Input.GetMouseButton as well, because otherwise AC will read the click before release. This updated script should do it:

    using UnityEngine;
    using AC;
    
    public class InputOverride : MonoBehaviour
    {
    
        void Start ()
        {
            KickStarter.playerInput.InputGetMouseButtonDownDelegate = My_GetMouseButtonDown;
            KickStarter.playerInput.InputGetMouseButtonDelegate = My_GetMouseButton;
        }
    
        private bool My_GetMouseButtonDown (int button)
        {
            if (button == 0 && KickStarter.playerInteraction.IsMouseOverHotspot ())
            {
                return Input.GetMouseButtonUp (0);
            }
            return Input.GetMouseButtonDown (button);
        }
    
        private bool My_GetMouseButton (int button)
        {
            if (button == 0 && KickStarter.playerInteraction.IsMouseOverHotspot ())
            {
                return false;
            }
            return Input.GetMouseButton (button);
        }
    
    }
    
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.