Forum rules - please read before posting.

Disable script on hotspot

Hi,

You made this excellent script for me that decides which interactive boundary activates a hotspot (see below) - but is there a way to add to this script to add the option to disable the script at some point through action list? Or the option to change the boundary on action script? Or would i simply object: call event and bool disable on DynamicInteractiveBoundary? See screenshot:

https://www.dropbox.com/s/bi1r8djj9vegpe8/DynamicInteractiveBoundary DIsable_Change boundary.png?dl=0

using UnityEngine;
using AC;

public class DynamicInteractiveBoundary : MonoBehaviour
{

    public string boolVarName;
    public InteractiveBoundary interactiveBoundary;
    public Hotspot hotspot;

    private void OnEnable ()
    {
        EventManager.OnAfterChangeScene += OnAfterChangeScene;
        EventManager.OnVariableChange += OnVariableChange;
    }

    private void OnDisable ()
    {
        EventManager.OnAfterChangeScene -= OnAfterChangeScene;
        EventManager.OnVariableChange -= OnVariableChange;
    }


    private void OnAfterChangeScene (LoadingGame loadingGame)
    {
        GVar variable = GlobalVariables.GetVariable (boolVarName);
        if (variable == null) { Debug.LogWarning ("Cannot find variable named " + boolVarName); return; }
        bool isOn = variable.BooleanValue;
        hotspot.interactiveBoundary = isOn ? null : interactiveBoundary;
    }


    private void OnVariableChange (GVar variable)
    {
        if (variable.label == boolVarName)
        {
            OnAfterChangeScene (LoadingGame.No);
        }
    }
}

Comments

  • Or would i simply object: call event and bool disable on DynamicInteractiveBoundary?

    Disabling the component will stop the script taking effect.

  • So it seems that using object: call event and bool disable on DynamicInteractiveBoundary isn't affecting anything, the hotspot is then still not active. Please see video:

    https://www.dropbox.com/s/ieoni8fut965dn1/HotspotDynamic.mov?dl=0

  • edited March 2022

    Disabling a component won't undo any changes its made - it just won't make any further changes.

    If you want to revert the Hotspot back to some original state, you can do so with code in the script's OnDisable function, which is called at the time that the component is disabled.

  • Thanks, are you able to help with that at all?

  • What state do you want the Hotspot to be in when the component is disabled?

  • edited March 2022

    I always want the hotspot on (apart from when the hotspot object has been picked up), but for the interactive boundary to change, so the example is, the scene has three sections and before different lamps are turned on the hotspots are enabled via three different dynamic boundaries, Once on re-entering scene, or when the lamps are lit, I want to call an action that ideally changes the dynamic boundary to one that is full width of scene, or just disables the script so it is not boundary specific

  • If you want to make the Hotspot not be boundary-specific when the above script is disabled, insert the following into its OnDisable function:

    hotspot.interactiveBoundary = null;
    
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.