So, I have just finished making dialogue boxes in my game, and for this first dialogue box, I need it to be so as soon as the dialogue box goes away (SetActive (false)), it brings up a menu, but for some reason I can’t figure out how to do that. I’ve done lots of similar things with other menus, but the problem is thus:
As there is need for this sort of thing in multiple places for different reasons, I’d like to have functionality so that when any dialogue box is SetActive (false) in the game, I have a way to call various functions from various scripts, kind of like the button UI inspector thing shown below:
But I can’t think of how to do that! I looked into Event Triggers, but it doesn’t have any events for disabling stuff… or enabling, for that matter.
At the very least, I’d like if I could just make this one box call something when I set it inactive.
//TriggerOnEnableChange.cs
using UnityEngine;
using UnityEngine.Events;
public class TriggerOnEnableChange : MonoBehaviour
{
[System.Serializable]
public class BoolEvent : UnityEvent<bool> { }
public UnityEvent onEnable;
public UnityEvent onDisable;
public BoolEvent onToggle;
private void OnEnable()
{
onEnable.Invoke();
onToggle.Invoke(true);
}
private void OnDisable()
{
onDisable.Invoke();
onToggle.Invoke(false);
}
}
Now you can assign a simple method to the onEnable or onDisable events. The onToggle event takes a bool parameter of the new state and is called both when the object is enabled or disabled.