Forum rules - please read before posting.

Trigger Action List from hotspot on hover (map)

Hello!
I've working on a map but instead of using the Menus (buttons) I tried to use the Hotspots so I could trigger action lists and make good use of all the things the hotspots have. I searched the forum for a solution and found something like this:

using UnityEngine;
using AC;

public class MouseOverHotspot : MonoBehaviour
{
public ActionList onHover;

private void OnEnable()
{
    EventManager.OnHotspotSelect += Hover;
}

private void OnDisable()
{
    EventManager.OnHotspotSelect -= Hover;
}

private void Hover(Hotspot hotspot)
{
    onHover.Interact();
}

}


To test it out simple, I created some sort of glow over the sprite (another sprite which turns visible). Unfortunately it only works on one hotspot disregarding which hotspot I'm hovering over.
I also created a second Action list so when it goes away from the hover, to run another action list to restore everything to normal. Practically same approach but in two different scripts.

Unfortunately, not even making one or two scripts for hotspots I could make it work.
The simple question is: how can I trigger an action list when hovering over a hotspot? And maybe another one when hovering away? If it's possible... of course.
By the way: I did look into the tutorial but we wanted to go a step further.

Thanks.
Latest AC. Unity 2020.3.38

Comments

  • edited September 2022

    If you want to have the "onHover" ActionList run for a specific Hotspot, you need to compare the function parameter with some value. If the script is attached to the Hotspot itself, for example, you can compare its gameObject:

    private void Hover (Hotspot hotspot)
    {
        if (hotspot.gameObject == gameObject)
        {
            onHover.Interact();
        }
    }
    
  • THANKS! Exactly what I was looking for. Thanks again for everything!

  • edited November 2023

    I have the same question. And i am a null knowledge beginner in looking at C# codes, finding them intersting though my experience with AC.

    Unity 2020.3.30f1
    AC 1.78.4
    I did not want this ability for AC Hotspots but for some Unity GameObjects with colider which can run actionlist onMoveEnter and OnMouseExit
    With lots of search and tutorials i managed to have this script:
    I think i am wrong with using KickStarter.
    Maybe i must use AC.AdvGame.Interact ?????
    and i was Hoping i can use RememberAnimator Component on them to keep track of their condition when scene changes or loads.

    using UnityEngine;
    using AC;
    
    public class HoverActionList : MonoBehaviour
    {
        [SerializeField]
        private ActionListAsset hoverActionList;
    
        [SerializeField]
        private ActionListAsset stopHoverActionList;
    
        void OnMouseEnter()
        {
            // Runs the hover ActionList when the mouse enters the object
            if (hoverActionList != null)
            {
                KickStarter.actionListManager.PlayActionList(hoverActionList);
            }
        }
    
        void OnMouseExit()
        {
            // Run the stop hover ActionList when the mouse exits the object
            if (stopHoverActionList != null)
            {
                KickStarter.ActionListManager.PlayActionList(stopHoverActionList);
            }
        }
    }
    
  • See the Manual's "Interaction scripting" chapter for details on how to run an ActionList through code.

    In short, you just need to call its Interact function:

    hoverActionList.Interact ();
    
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.