Forum rules - please read before posting.

About Player-vicinity detection

Hello ChrisIce.I am making a 2D mobile game.My current Hotspot detection method setting is Player-vicinity. Players need to walk near the hotspot and manually click on it to display the interactive menu. I hope the interactive menu will automatically appear in nearby hotspots when the player moves.How do I do it.Thank you.

Comments

  • What are your AC and Unity versions?

    I'll need to see your Settings Manager in full - can you share screenshots?

  • edited February 17

    AC1.74.5,unity2021.3.46f1

  • edited February 17
    SuperXu, when Chris requests Settings manager, he means under the AC game manager tab, select, "settings" and screenshot that whole thing, this looks incomplete to me? Although the images you shared might also be useful.
  • Okay, I've hidden the settings that I thought were irrelevant. I will submit a complete image later.

  • To allow for this behaviour on touch-screen, attach the following script to your Player and fill in its Inspector:

    using UnityEngine;
    using AC;
    
    public class AutoShowInteractions : MonoBehaviour
    {
    
        public DetectHotspots hotspotDetector;
    
        void Update ()
        {
            if (hotspotDetector.NearestHotspot && KickStarter.stateHandler.IsInGameplay ()) {
                KickStarter.playerInteraction.SetActiveHotspot (hotspotDetector.NearestHotspot);
                KickStarter.playerMenus.EnableInteractionMenus (hotspotDetector.NearestHotspot);
            }
        }
    
    }
    

    This requires the latest AC update to be imported, however.

  • thank you,ChrisIce.This is very helpful to me. In fact, I need to display all the hotspots near the player instead of the nearest one. I tried to make modifications, and it displayed normally when there was only one hotspot near the player. When there are two or more hotspots, neither will be displayed. Is there any related setting that restricts the hiding of the Interaction menu.
    `using UnityEngine;
    using AC;

    public class AutoShowInteractions : MonoBehaviour
    {

    public DetectHotspots hotspotDetector;
    private int m_Lenth;
    void Update()
    {
        if (KickStarter.stateHandler.IsInGameplay())
        {
            m_Lenth = hotspotDetector.GetAllDetectedHotspots().Length;
            Debug.Log( m_Lenth );
             for ( int i = 0; i < m_Lenth; i++ )
            {
                Hotspot hotspot = hotspotDetector.GetAllDetectedHotspots()[i];
                Debug.Log(hotspot.name);
                if (hotspot.enabled )
                {
                    KickStarter.playerInteraction.SetActiveHotspot(hotspot);
                    KickStarter.playerMenus.EnableInteractionMenus(hotspot);
                }
            }
        }
    }
    

    }`

  • SetActiveHotspot only supports one Hotspot at a time.

    It ought to be able to enable multiple interaction menus at a time by - through code - duplicating a Menu, initialising it for a given Hotspot, and turning it on. Something like:

    var newMenu = ScriptableObject.CreateInstance<Menu> ();
    var menuToCopy = PlayerMenus.GetMenuWithName ("Interaction");
    myMenu.CreateDuplicate (menuToCopy);
    newMenu.MatchInteractions (hotspot, false);
    newMenu.TurnOn ();
    
  • edited February 19

    Thank you,Chris.This seems quite complex and requires object pooling to manage all Interaction Menu. I want to change the interaction design. Instead of directly displaying the interaction menu, a unified icon is displayed on all Hotspots within the scope of Hotspot Detector. The purpose of this icon is to prompt players that there is a Hotspot where they can interact, and when this icon is clicked, the interaction menu will be displayed. I found that setting the "Display Hotspot icons" to "only when highlighting“ and then adding Highlight Component for each Hotspot can effectively implement my idea. But my game completion rate is relatively high, with a considerable number of Hotspots scattered across different scenes, resulting in a very heavy workload. Do you know any simple methods?

  • edited February 20

    Thank you,Chris.I have found a solution.But I encountered a new problem. After I click the interaction menu button, the highlight icon will reappear and quickly disappear.

  • Does this occur as a result of any scripting? I'll need to know the solution you found.

  • I didn't scripting.
    My solution: Set the 'Display Hotspot icons‘ to 'Only When Highlighting', and then add a highlight component for each hotspot and assigning it to the ’ object to highlight' field of the hotspot component.

  • edited February 21

    Does this issue occur in the latest release? Import it into a duplicate/backup project.

    Share screenshots of your updated Settings Manager and Interaction menu.

  • Hello Chris.I found that the problem is with the CanDisplayHotspotIcon() function in Hotpost. After clicking the interaction button, KickStarter. stateHandler IsInGameplay() did not immediately turn false. The source of InteractionUI is Unity UI Prefab. As is well known, clicking on the interaction button or clicking on other areas will close the Interaction UI. But I found that these two closing methods in PlayerMenu use the same function. My question is, is there currently a way to determine whether the interactive button or non interactive area is closed when closing Interaction UI? This is crucial for me to solve the current problem.

  • I'm not following the connection between the two, but you can try hooking into the OnMenuTurnOff event and checking if the mouse is over an interaction menu:

    void OnEnable () => EventManager.OnMenuTurnOff += OnMenuTurnOff;
    void OnDisable () => EventManager.OnMenuTurnOff -= OnMenuTurnOff;
    
    void OnMenuTurnOff (Menu menu, bool isInstant)
    {
        if (menu.title == "Interaction")
        {
            Debug.Log (KickStarter.playerMenus.IsMouseOverInteractionMenu ());
        }
    }
    
  • Thank you,Chris.I found the reason for the Hotspot icon flashing. There is a vacuum period of over ten frames after clicking the interaction button and before the ClickButton function in PlayerInteraction is executed. During this vacuum period, the icon was rendered.

  • That may have since been addressed in the latest release - you'll need to import it into a backup/duplicate project and see if the issue persists.

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.