public void changeUI(GameObject ui) { if (currentUI != null) { currentUI.EndUI(); } if (ui != null) { currentUI = ui.GetComponent <UIState>(); if (currentUI != null) { currentUI.StartUI(); } else { Debug.LogError("Gameobject: " + ui.name + "is not a UI state"); } } }