Can a Unity script listen for events and the active self under certain circumstances?

I want to create a general warning window to display information about some information, possibly a warning, a tutorial, etc.,

I think it will be good if there is a way for the warning widget (basically, only the window frame, close button, information text and some tips) to appear when the event is received, so in I could just take off msg via the static method , and the widget could just appear.

I have no problems with the execution of part of the event, but I could not find a way to activate the game object of the widget, since it will be deactivated as the game starts and, it seems, cannot assign itself an event pool.

Is there any way to do this? Or how do you deal with the problem?

enter image description here

And so the appointment of the event is still complete:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class WarningTextUGUIController : MonoBehaviour { private Text text; // Use this for initialization void Start () { text = GetComponent<Text>(); text.text = ApplicationModel.CurrentErrMsg; ApplicationModel.OnErrMsg += ChangeErrMsg; } private void ChangeErrMsg(string msg, bool isNgui) { if (!isNgui) { text.text = msg; if (!gameObject.transform.parent.parent.gameObject.activeSelf) { gameObject.transform.parent.parent.localScale = new Vector3(0f, 0f, 0f); gameObject.transform.parent.parent.gameObject.SetActive(true); LeanTween.scale(gameObject.transform.parent.parent.gameObject, new Vector3(1f, 1f, 1f), 0.2f).setEase(LeanTweenType.easeInBounce); } } } private void OnDestroy() { ApplicationModel.OnErrMsg -= ChangeErrMsg; } } 

I should note that everything will work if I make the widget active at the beginning of the game, but I have to disable it, because it should not be displayed in most cases.

+1
c # events unity3d
source share

No one has answered this question yet.

See similar questions:

2
Unity EventManager with delegate instead of UnityEvent
0
Find Inactive GameObject by Name, Tag or Layer

or similar:

792
How to find event listeners on a DOM node when debugging or from JavaScript code?
104
JavaScript: remove event listener
97
Disable Required validation attribute under certain circumstances
4
How to add Persistent Listener to Button.onClick in Unity Script Editor
2
Unity GUIText on C # Collision
0
Unity: Why does adding an event listener work only in the Awake function?
0
Listening to events only in certain circumstances
0
Unity, Global Event, Global Listener or GM.Find () in a stream
0
Unity Listener / Event, like OnValueChanged for GameObject properties
0
How to convert keyboard controls to touch screen in Unity

All Articles