The problem is that when trying to check CurrentMenu
property from MainCameraMove
it always returns null even if previously _currentMenu
definitely was set by invoking ShowMenu
function. Does unity somehow clears objects on its like?
public class MenuManager {
private Menu _currentMenu;
public Menu CurrentMenu
{
get { return _currentMenu; }
set { _currentMenu = value; }
}
private static MenuManager instance = null;
public static MenuManager Instance
{
get
{
if (instance == null)
{
instance = new MenuManager();
}
return instance;
}
}
public void ShowMenu(Menu menu)
{
HideAllMenus();
_currentMenu = menu;
menu.IsOpen = true;
}
}
public class MainCameraMove : MonoBehaviour
{
if (MenuManager.Instance.CurrentMenu == null)
{...}
}
UPDATE: Thanks everyone for suggestions. I’ve found the bug. Other function was called from Update() that instantly got the currentMenu
property to null