Forum rules - please read before posting.

Different context-sensitive interactions for specific Hotspots, when multiple Hotspots are on?

edited July 2020 in Technical Q&A

[Unity 2019.4.1f1 - AC 1.71.5]

Hello!

I'm testing with having multiple Hotspots show up on the screen as the Player gets in their vicinity and, so far, so good.

I'm having a little harder time trying to figure out the best way to have different Hotspots react to different Input keys.

In other words, I want to associate different Interaction buttons (e.g. A, B, X, Y) to each Hotspot so that even if multiple Hotspots are currently on, I can choose which one to interact with by hitting the associated Interaction.

I have been using the Simultaneous Hotspot labels script available in the wiki, and edited it to add the following line in the ShowForHotspot() method.

(myMenu.GetElementWithName("Graphic") as MenuGraphic).graphic = AC.KickStarter.cursorManager.GetCursorIconFromID(hotspotToShow.GetFirstUseIcon());

I'm using a Unity UI for my Hotspot UI. I'm integrating the new Unity Input System so my scene has a GameObject carrying the integration script and the InteractionX\InteractionY are both set up in it.

The UI has a Graphic element, to show which button (e.g. A, B, X, Y) should be pressed in order to interact with it.

Since all these Hotspots will likely only have a Single 'Use' interaction setup, I think I don't really need to make use of the Interaction Menu. I have created all my custom Interactions in it just in case, but I'm not sure I want it to show up.

I tried, by the way, considering using the Proximity-based Interaction menus as provided in the wiki, editing it like this:

private void Update()
{
    // Check if there is a player with a hotspot detector
    if (KickStarter.player != null && KickStarter.player.hotspotDetector != null)
    {
        // Read all the Hotspots detected by the detector
        Hotspot[] hotspotsDetected = KickStarter.player.hotspotDetector.GetAllDetectedHotspots();

        if (hotspotsDetected.Length > 0 && KickStarter.stateHandler.IsInGameplay())
        {
            for (int i = 0; i < hotspotsDetected.Length; i++)
            {
                // If there are Hotspots nearby, and it's during gameplay, show Interaction menus for those Hotspots
                KickStarter.playerMenus.EnableInteractionMenus(hotspotsDetected[i]);
            }
        }
        else
        {
            // Otherwise, close Interaction menus
            KickStarter.playerMenus.CloseInteractionMenus();
        }
    }
}

Therefore setting the Interaction Method to Custom Script and having an actual Interaction Menu, but I wasn't able to make it work.

I wonder: can this be done in some way that makes it more "seamless" with AC's default interaction system or should I make some event check for OnHostpotInteract and execute the RunUseInteraction() accordingly? If so, how should I tackle the check for the correct Interaction keypress (I know that AC uses InputGetButton())?

Thanks a lot in advance!

Comments

  • If using an Interaction menu, you can have each Interaction element respond to a different input button - but if you're using single 'Use' interactions then it's best to rely on custom scripting. This'll also be necessary if you want to make the inputs dynamic, so that e.g. two Hotspots never ask for the same input button.

    Adapting the Simultaneous Hotspot Labels script would be a good way to start, since you can detect input in its Update function:

    if (KickStarter.stateHandler.IsInGameplay () && myMenu != null && myMenu.IsOn ())
    {
        if (Input.GetButtonDown ("InteractionA"))
        {
            hotspotToShow.RunUseInteraction ();
        }
    }
    

    You don't need to rely on AC's InputGetButton functions - that's just so that it can be remapped.

    This'll work for InteractionA, but you'll need to figure out how you want to change the intended input. If you wanted the input to always be the same for a given Hotspot, you could replace "InteractionA" with a public string variable that you then set in its Inspector.

  • edited July 2020

    Yeah, I guess this is probably best approach. I think I'll use the icon ID and convert it into the according axis name.

    Thanks a lot again!

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.