Forum rules - please read before posting.

Action script from a mouse/cursor Roll Over

I think I’m being stupid, but how do I trigger an action script from a mouse/cursor Roll Over? I have regular hotspots that have mouse click activated scripts but occasionally I want to run something as the mouse just passes over it. Can’t think how to do it in AC?

Comments

  • You'd have to rely on custom scripting, but not much.

    To invoke an ActionList, call its Interact() method.

    To run code when a Hotspot is selected (i.e. mouse-overed), hook into the OnHotspotSelect custom event.

    Sample script (MouseOverInteraction.cs), that gets attached to the Hotspot:

    using UnityEngine;
    using AC;
    
    public class MouseOverInteraction : MonoBehaviour
    {
    
        public ActionList actionList;
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += MySelect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect += MySelect;
        }
    
        private void MySelect (Hotspot hotspot)
        {
            if (GetComponent <Hotspot>() == hotspot)
            {
                actionList.Interact ();
            }
        }
    
    }
    
  • Thank you, I'll give that a try :smile:

  • Hey @ChrisIceBox in OnDisable() it should unregister the MySelect right?!
    private void OnDisable () { EventManager.OnHotspotSelect -= MySelect; }

  • Yes - that was a typo.

  • The script works very well to trigger an assigned AC action list on mouse rollover – So I wondered if it possible to extend it to also create the action of On Mouse Leave?

    What I’m trying to achieve is when a mouse cursor enters the region of the hotspot, one action list runs (this it does), but when the play move the mouse off of the hotspot a different action list runs also.

    But... I’m not sure how to extend the code. This is seeming creating a hybrid of Trigger and Hotspot.

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.