Forum rules - please read before posting.

Menu button responds to mouse over?


Hi everyone,

sorry if this has been asked before, couldn't find it anywhere! :)

Is there a way to make a Unity UI Prefab menu with a button that triggers an action list on mouse over?

All I'm seeing at the moment is Responds to:
- Pointer Click
- Pointer Down

Comments

  • Welcome to the community, @barbara.

    You can't do it through the Menu Manager, but it is possible to run an ActionList / any code when the mouse hovers over an element by using custom events.

    Specifically, you want the OnMouseOverMenu event (see the end of the Manual's Section 11.4).  To run an ActionList through code, call its Interact function.  The kind of event you'd want to hook up, therefore, would be something like this:

    public AC.ActionListAsset myActionListAsset;
    public string menuName = "MyMenu";
    public string elementName = "MyButton";

    private void OnMouseOverMenu (AC.Menu _menu, AC.MenuElement _element, int _slot)
    {
        if (_menu.title == menuName && _element.title == elementName)
        {
            myActionListAsset.Interact ();
        }
    }


    Follow the linked tutorial and adapt it to run the OnMouseOverMenu event instead, using the code above.  Then place it in the scene by attaching it to an empty GameObject, assign the three fields in the Inspector, and you should be able to get the ActionList Asset to run whenever the mouse hovers over it.

    I don't know how experienced with coding you are, so please don't hesitate to ask if you need more assistance.
  • Hi @Chris and thanks for the quick answer!

    Unfortunately I have 0 coding knowledge so I was hoping there was a way of getting it as an option in the menu manager :-D

    At the moment I have a workaround with a menu with a static button, then a menu that appears on mouseover over it, which performs an action (including closing the menu with the static button). But it quickly becomes complicated with 20+ menus because I have a complicated inventory system.

    Would this solution (if I manage to make it work) mean I have to add it this empty object for every menu and every scene? 

  • Only for every scene - and you could attach it you e.g. your Player to have it survive scene changes.

    I'll look into adding this as an additional option in the upcoming v1.59a release, however.
  • Oh cool! I'm sorry to report I tried the custom code but didn't get anywhere.

    It would be fantastic if it's an option in the next release!
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.