Forum rules - please read before posting.

Mouse over and Vicinity with Method Point and Click

Hi,

I use the Point and click movement method and I wanted to know if in addition to Mouse over for the hotspot detection method, I could use Vicinity because I would have wanted the hotspot icons to be visible if the player is nearby.

Thank you for your feedback.

Comments

  • You can use the Detect Hotspots component to gather up nearby Hotspots, but you'd need to use Mouse Over method alongside a custom script that shows the icons of those within the Detect Hotspot's vicinity.

    Something like this, attached to the Player:

    using UnityEngine;
    using AC;
    
    public class ShowNearbyHotspots : MonoBehaviour
    {
    
        public DetectHotspots detectHotspots;
    
        void Update()
        {
            var nearbyHotspots = detectHotspots.GetAllDetectedHotspots();
            foreach (var hotspot in KickStarter.stateHandler.Hotspots)
            {
                if (hotspot == null || hotspot.highlight == null) continue;
                bool showIcon = hotspot.IsOn () && KickStarter.stateHandler.IsInGameplay() && IsNearby(hotspot);
                SetIconState(hotspot, showIcon);
            }
    
            bool IsNearby(Hotspot hotspot)
            {
                foreach (var nearbyHotspot in nearbyHotspots)
                {
                    if (nearbyHotspot == hotspot) return true;
                }
                return false;
            }
    
            void SetIconState(Hotspot hotspot, bool show)
            {
                if (show)
                {
                    hotspot.highlight.flashHoldTime = 1000f;
                    hotspot.highlight.Flash ();
                }
                else
                {
                    hotspot.highlight.CancelFlash ();
                }
            }
        }
    
    }
    
  • edited September 25

    Hi,

    Thank you for the answer but I didn't fully understand.

    I added the script to the player but what do I need to add in the "Detect Hotspot" field ?
    Do I also need to add a Hotspot Detector component ?

  • Yes - the component that's just underneath it. Drag the "Hotspot detector" label into that empty field.

    Both components need to be on a separate, child object of the Player, however. See this tutorial for details on what modifications need be made to your Player.

  • Yes, thank you, it works very well now.

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.