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.

  • edited July 19

    Triggers are not involved here - they involve physical objects in the scene being detected, not the mouse.

    The OnHotspotDeselect can similarly be used to run an ActionList when the mouse leaves a Hotspot.

    using UnityEngine;
    using AC;
    
    public class MouseOverInteraction : MonoBehaviour
    {
    
        public ActionList actionListOnEnter;
        public ActionList actionListOnExit;
    
        private void OnEnable ()
        {
            EventManager.OnHotspotSelect += MySelect;
            EventManager.OnHotspotDeselect += MyDeselect;
        }
    
        private void OnDisable ()
        {
            EventManager.OnHotspotSelect -= MySelect;
            EventManager.OnHotspotDeselect -= MyDeselect;
        }
    
        private void MySelect (Hotspot hotspot)
        {
            if (GetComponent <Hotspot>() == hotspot)
            {
                actionListOnEnter.Interact ();
            }
        }
    
        private void MyDeselect (Hotspot hotspot)
        {
            if (GetComponent <Hotspot>() == hotspot)
            {
                actionListOnExit.Interact ();
            }
        }
    
    }   
    
  • Thanks for the code. Unfortunately I seem to get my exit hotspot AC action list running when entering a hotspot with the mouse (as well as the action list on entering). Do I need to set my action lists to any specific setting? I tried alternating between run in background and pause.

  • No, it was my fault for coding too early in the morning. I've updated the above post - give it another go.

  • Works like a charm! Thank you :) <3 This is going to be such a useful extension to the Adventure Creator toolkit for my projects.

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.
Do NOT follow this link or you will be banned from the site!