I have attached a UI prefab inside the Dialogue Manager -> Instantiate prefabs -> prefabs.
Inside the UI parent, I have a script which I am interested to make it as a "global accessor". So every script inside the game, if it needs it, they can access to their functions. To test if it can access various scripts, I have written one function that changes the UI visibility:
Code: Select all
public class MManager : MonoBehaviour {
private static MManager m_Instance;
public static MManager GetInstance()
{
return m_Instance;
}
// All the child panels
public GameObject m_Child;
private void Awake()
{
m_Instance = this;
}
public void SetOpen(bool value)
{
m_Child.SetActive(value);
}
}
Code: Select all
public class TestMCall : MonoBehaviour
{
private void Update()
{
if (MManager.GetInstance() != null)
{
if (Input.GetKeyDown(KeyCode.E))
{
if (!MManager.GetInstance().m_Child.activeInHierarchy)
MManager.GetInstance().SetOpen(true);
else
MManager.GetInstance().SetOpen(false);
}
}
}
}
Code: Select all
public class MLoadScene : MonoBehaviour {
public void LoadLevel(int scene)
{
StartCoroutine(LoadAsync(scene));
}
IEnumerator LoadAsync(int scene)
{
MManager.GetInstance().SetOpen(false);
AsyncOperation async = SceneManager.LoadSceneAsync(scene);
while (!async.isDone)
{
yield return null;
}
}
}
Thanks!