Forum rules - please read before posting.

How to turn off hotspot AND disable interaction

Hi. I am using AC 1.71.4 on Unity 2018.1.0f2 and making a 2D game.
I am using the 'Choose Hotspot then Interaction' method of accessing hotspots.

I have an animation set up of a bird that sits on the window sill, flies away and then comes back.

The bird's hotspot is set up as a child of the animation, so I can turn it off when the bird flies away (because you can access the children of game objects from the root)

This is working fine BUT... if the player has already selected the bird but not yet chosen the interaction I.e. they can see the hand and the speech bubble icons for 'use' and 'talk', then, when the bird flies away, the interaction is still available.

How do I turn this off? Thanks.

Comments

  • Rather than turning off the Hotspot through animation, use a separate Hotspot: Enable or disable Action. This way, the OnHotspotTurnOff custom event will be triggered, allowing you to use a simple script to turn off the interaction menu:

    using UnityEngine;
    using AC;
    
    public class TurnOffHotspotInteraction : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnHotspotTurnOff += OnHotspotTurnOff; }
    
        private void OnDisable () { EventManager.OnHotspotTurnOff -= OnHotspotTurnOff; }
    
        private void OnHotspotTurnOff (Hotspot hotspot)
        {
            if (hotspot == GetComponent <Hotspot>() && KickStarter.playerInteraction.GetLastOrActiveHotspot () == hotspot)
            {
                KickStarter.playerMenus.CloseInteractionMenus ();
            }
        }
    
    }
    

    Paste that into a C# script named TurnOffHotspotInteraction.cs and attach it to the Hotspot. The interaction menu(s) should turn off automatically when the Hotspot is turned off.

  • Great, thanks. I did that - but unfortunately so far it doesn't seem to be working... I have probably misunderstood something.

    Here is an image of my Unity screen with the hotspot selected. https://imgur.com/TCOWPt2

    You can see the Hotspot Enabled/Disabled action in the animation window which is set to switch off when the animated crow leaves the scene. You can also see I have attached the new script to this hotspot.

    Perhaps I have attached the Hotspot Enabled/Disabled action in the wrong way?

  • Disabling the Hotspot component in animation is not equaivalent to using the Hotspot: Enable or disable Action. Though they might appear to have the same effect, the latter will allow the OnHotspotTurnOff event to be triggered so that the code will run.

    My suggestion was to remove this animation property, and run that Action separately at the same time the animation is run.

    Alternatively, you can rely on animation events to trigger a script function at the same time:

    using UnityEngine;
    using AC;
    
    public class TurnOffHotspotInteraction : MonoBehaviour
    {
    
        public void CloseIfActive ()
        {
            if (KickStarter.playerInteraction.GetLastOrActiveHotspot () == GetComponent <Hotspot>())
            {
                KickStarter.playerMenus.CloseInteractionMenus ();
            }
        }
    
    }
    

    Keeping your animation property that disables the Hotspot, replace your script with the above, and create an Animation event that triggers this script's CloseIfActive function.

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.