Forum rules - please read before posting.

Hotspot Icon

Hello everyone

It seems I have notched something which I'm not sure if it is a bug or not. When the player stand in front of a hotspot and the hotspot icon appears, the player would be block the icon I believe the icon should be visible on top of anything. I also have as second manner, is there a possible way that we can have an additional icons that within a specific radius these icons
should appear to locate near by hotspot objects.

Please check the uploaded videos for more details

1.
2,

«1

Comments

  • the player would be block the icon

    Do you have Hide icons behind Colliders? unchecked in your Settings Manager? That should prevent the the presence of any colliders getting in the way of an icon's display.

    What are your AC/Unity versions, and can you share your Settings Manager?

    is there a possible way that we can have an additional icons that within a specific radius these icons should appear to locate near by hotspot objects.

    If you switch to "Player Vicinity" Hotspot detection (see this tutorial), all Hotspots within the detector will display their icon.

    For an icon to display, however, it must also be interactive. If you want icons to display even when not interactive (i.e. because the Player is too far away), you would need to rely on custom scripting to render them instead.

  • Do you have Hide icons behind Colliders? unchecked in your Settings Manager? That should prevent the the presence of any colliders getting in the way of an icon's display.

    Yes I have Hide icons behind Colliders unchecked. Still the player standing in front of the icon would hide it.

    What are your AC/Unity versions, and can you share your Settings Manager?

    -I have Unity version 2020.1.6
    -Latest AC version.
    -Here is screen shots of my setting manager:

    https://imgur.com/ZD1YsRV
    https://imgur.com/z9dxLbm
    https://imgur.com/LbNA6ow
    https://imgur.com/ffIhRry
    https://imgur.com/ujWbis9

  • you would need to rely on custom scripting to render them instead.

    I'm not really too familiar with custom scripting.. Isn't there other easier way?

    For example: display hotspot icon should be -when close by a hotspot- show "inspect icon" and when -touching the hotspot- show "Use icon". This should be very useful to AC as well because sometimes the players wouldn't know if there are any interactions around unless they touch the hotspot..

  • edited June 2022

    Yes I have Hide icons behind Colliders unchecked. Still the player standing in front of the icon would hide it.

    You're rendering the icon in World Space, so it'll be bound by your MainCamera's "Near Clip Plane" field.

    Pause the game when this occurs, and look for the object with the name "Hotspot - icon" (replacing Hotspot with the name of your Hotspot). Check its position - is it too close to the camera? Does this occur if you use Screen Space instead?

    I'm not really too familiar with custom scripting.. Isn't there other easier way?

    I can assist, but I'll need more clarity on what you're after - what do you mean by "touching the hotspot"? As in, close enough to interact - with the "inspect icon" only showing when nearby but too far to interact with?

  • This script, attached to a Hotspot, allows an icon to show independently of the built-in icon system:

    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class HotspotIcon : MonoBehaviour
    {
    
        [SerializeField] private float minDistanceToPlayer = 20f;
        [SerializeField] private float alphaSpeed = 5f;
        [SerializeField] private Texture iconTexture = null;
        [SerializeField] private bool useDistanceFromCamera;
        private Hotspot hotspot;
        private float targetAlpha;
        private float alpha;
        private CursorIcon icon;
    
        private void Start ()
        {
            icon = new CursorIcon ();
            icon.ReplaceTexture (iconTexture);
    
            hotspot = GetComponent<Hotspot> ();
        }
    
    
        private void Update ()
        {
            if (KickStarter.player == null) return;
    
            if (!KickStarter.stateHandler.IsInGameplay ())
            {
                targetAlpha = 0f;
            }
            else
            {
                Vector3 playerPosition = useDistanceFromCamera ? Camera.main.transform.position : KickStarter.player.transform.position;
                float distanceToPlayer = (hotspot.GetIconPosition () - playerPosition).sqrMagnitude;
                bool isCloseEnough = distanceToPlayer <= minDistanceToPlayer;
                targetAlpha = isCloseEnough ? 1f : 0f;
            }
    
            alpha = Mathf.Lerp (alpha, targetAlpha, Time.deltaTime * alphaSpeed);
        }
    
    
        private void OnGUI ()
        {
            if (alpha <= 0f) return;
    
            Color c = GUI.color;
            Color tempColor = c;
            c.a = alpha;
            GUI.color = c;
    
            icon.Draw (hotspot.GetIconScreenPosition ());
    
            GUI.color = tempColor;
        }
    
    }
    
  • Does this occur if you use Screen Space instead?

    I changed it to -screen space- and it worked. Nothing blocks the icon now, thanks.

    I can assist, but I'll need more clarity on what you're after - what do you mean by "touching the hotspot"? As in, close enough to interact - with the "inspect icon" only showing when nearby but too far to interact with?

    Well, by that I mean when the hotspot detector touches the hotspot itself, then the Inspect icon would disappear and the "use icon" would show instead. Kindly check the first video I sent. When the player comes close to a hotspot, the "Inspect Icon" would appear on nearby hotspots, then, when the player's hotspot detector comes in contact with the hotspot, the" use icon" should appear.

  • Kindly check the first 10 seconds only.

    When nearby the "inspect icon" appeared. (to tell the player that there is something to interact with here) then when the player actually came in contact with the hotspot the "use icon" appeared.

  • The script above will allow for the "inspect icon", behaviour in the video, leaving AC's built-in Hotspot icons for the "use icon" behaviour.

  • Beautiful script. Works great.
    Just two minor issues:

    The first one, I can't seem to be able to change the size of the icon. It looks big.

    The second issue, when the player gets in contact with the hotspot the "Inspect Icon" does not disappear, its still there and blocking the "Use Icon"

  • Oh also another issue is, the "Inspect Icon" would still appear even if the hotspot is turned off

  • edited July 2022
    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class HotspotIcon : MonoBehaviour
    {
    
        [SerializeField] private float minDistanceToPlayer = 20f;
        [SerializeField] private float alphaSpeed = 5f;
        [SerializeField] private Sprite iconSprite = null;
        [SerializeField] private bool useDistanceFromCamera;
        private Hotspot hotspot;
        private float targetAlpha;
        private float alpha;
    
        [SerializeField] private string iconSortingLayer;
        [SerializeField] private int iconSortingOrder;
        private SpriteRenderer iconRenderer;
    
    
        private void Start ()
        {
            hotspot = GetComponent<Hotspot> ();
        }
    
    
        private void Update ()
        {
            if (KickStarter.player == null) return;
    
            if (!KickStarter.stateHandler.IsInGameplay () || !hotspot.IsOn () || KickStarter.playerInteraction.GetActiveHotspot () == hotspot)
            {
                targetAlpha = 0f;
            }
            else
            {
                Vector3 playerPosition = useDistanceFromCamera ? Camera.main.transform.position : KickStarter.player.transform.position;
                float distanceToPlayer = (hotspot.GetIconPosition () - playerPosition).sqrMagnitude;
                bool isCloseEnough = distanceToPlayer <= minDistanceToPlayer;
                targetAlpha = isCloseEnough ? 1f : 0f;
            }
    
            alpha = Mathf.Lerp (alpha, targetAlpha, Time.deltaTime * alphaSpeed);
    
            DrawIconWorldSpace ();
        }
    
    
        private void DrawIconWorldSpace ()
        {
            if (iconRenderer == null)
            {
                GameObject iconOb = new GameObject (this.name + " - icon");
                iconRenderer = iconOb.AddComponent <SpriteRenderer>();
                iconOb.transform.localScale = Vector3.one * (25f * KickStarter.settingsManager.hotspotIconSize);
    
                if (!string.IsNullOrEmpty (iconSortingLayer))
                {
                    iconRenderer.GetComponent <SpriteRenderer>().sortingLayerName = iconSortingLayer;
                }
                iconRenderer.GetComponent <SpriteRenderer>().sortingOrder = iconSortingOrder;
                iconRenderer.sprite = iconSprite;
            }
    
            iconRenderer.transform.position = hotspot.GetIconPosition ();
            iconRenderer.transform.LookAt (iconRenderer.transform.position + KickStarter.mainCamera.Transform.rotation * Vector3.forward, KickStarter.mainCamera.Transform.rotation * Vector3.up);
    
            Color tempColor = iconRenderer.color;
            tempColor.a = alpha;
            iconRenderer.color = tempColor;
        }
    
    }
    
  • I tried it, the Icon does not appear anymore..

  • Try it now. Note the change from icon texture to sprite in the Inspector.

  • The script works perfectly, but the only issue is that the player could hide or block the icon when he's in front of it.

  • With this technique - as with World Space - the icon is rendered using a Sprite Renderer as a 3D object in the scene. Define a new Layer and assign it as the "Icon Sorting Layer" to render it above other objects.

  • I created a new layer and assigned it as the "Icon sorting layer" however, the player still blocks the inspect icon

  • edited July 2022

    That may be down to your Materials / Render Pipeline, in that case.

    You could try assigning a new Material to the SpriteRenderer it generates, or try this alternative that goes back to the original method but scales the texture:

    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class HotspotIcon : MonoBehaviour
    {
    
        [SerializeField] private float minDistanceToPlayer = 10f;
        [SerializeField] private float minSize = 0.015f;
        [SerializeField] private float maxSize = 0.045f;
        [SerializeField] private float alphaSpeed = 5f;
        [SerializeField] private Texture iconTexture = null;
        [SerializeField] private bool useDistanceFromCamera;
        private Hotspot hotspot;
        private float targetAlpha;
        private float alpha;
        private CursorIcon icon;
    
    
        private void Start ()
        {
            hotspot = GetComponent<Hotspot> ();
            icon = new CursorIcon ();
            icon.ReplaceTexture (iconTexture);
        }
    
    
        private void Update ()
        {
            if (KickStarter.player == null) return;
    
            Vector3 playerPosition = useDistanceFromCamera ? Camera.main.transform.position : KickStarter.player.transform.position;
            float distanceToPlayer = (hotspot.GetIconPosition () - playerPosition).magnitude;
            icon.size = Mathf.Lerp (maxSize, minSize, distanceToPlayer / minDistanceToPlayer);
    
            if (!KickStarter.stateHandler.IsInGameplay () || !hotspot.IsOn () || KickStarter.playerInteraction.GetActiveHotspot () == hotspot)
            {
                targetAlpha = 0f;
            }
            else
            {
                bool isCloseEnough = distanceToPlayer <= minDistanceToPlayer;
                targetAlpha = isCloseEnough ? 1f : 0f;
            }
    
            alpha = Mathf.Lerp (alpha, targetAlpha, Time.deltaTime * alphaSpeed);
        }
    
    
        private void OnGUI ()
        {
            if (alpha <= 0f) return;
    
            Color c = GUI.color;
            Color tempColor = c;
            c.a = alpha;
            GUI.color = c;
            icon.Draw (hotspot.GetIconScreenPosition ());
    
            GUI.color = tempColor;
        }
    
    }
    
  • Works like a charm! Thank you for your consistent support. I'll experiment with it more and let you know if anything else comes up

  • I discovered a bug with this script. When using -Engine-Manage Systems- and turn Interactions to "Disable" the icon still appears. Same thing when pausing using adventure creator menu "Pause" the icon doesn't disappear and remain active.

    Here is a video to further explain the bug.

    Also, for the original hotspot icon when setting the display icon to "Highlighting" and then disable interactions when the icon is highlighting it will remain active until you enable interactions again.

  • Try this:

    using UnityEngine;
    using AC;
    
    [RequireComponent (typeof (Hotspot))]
    public class HotspotIcon : MonoBehaviour
    {
    
        [SerializeField] private float minDistanceToPlayer = 10f;
        [SerializeField] private float minSize = 0.015f;
        [SerializeField] private float maxSize = 0.045f;
        [SerializeField] private float alphaSpeed = 5f;
        [SerializeField] private Texture iconTexture = null;
        [SerializeField] private bool useDistanceFromCamera;
        private Hotspot hotspot;
        private float targetAlpha;
        private float alpha;
        private CursorIcon icon;
    
    
        private void Start ()
        {
            hotspot = GetComponent<Hotspot> ();
            icon = new CursorIcon ();
            icon.ReplaceTexture (iconTexture);
        }
    
    
        private void Update ()
        {
            if (KickStarter.player == null) return;
    
            Vector3 playerPosition = useDistanceFromCamera ? Camera.main.transform.position : KickStarter.player.transform.position;
            float distanceToPlayer = (hotspot.GetIconPosition () - playerPosition).magnitude;
            icon.size = Mathf.Lerp (maxSize, minSize, distanceToPlayer / minDistanceToPlayer);
    
            if (!KickStarter.stateHandler.CanInteract () || !KickStarter.stateHandler.IsInGameplay () || !hotspot.IsOn () || KickStarter.playerInteraction.GetActiveHotspot () == hotspot)
            {
                targetAlpha = 0f;
            }
            else
            {
                bool isCloseEnough = distanceToPlayer <= minDistanceToPlayer;
                targetAlpha = isCloseEnough ? 1f : 0f;
            }
    
            alpha = Mathf.Lerp (alpha, targetAlpha, Time.unscaledDeltaTime * alphaSpeed);
        }
    
    
        private void OnGUI ()
        {
            if (alpha <= 0f) return;
    
            Color c = GUI.color;
            Color tempColor = c;
            c.a = alpha;
            GUI.color = c;
            icon.Draw (hotspot.GetIconScreenPosition ());
    
            GUI.color = tempColor;
        }
    
    }
    
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.