private void OnScreenChanged(string from, string to) { // Assign all variables mainUIPanel = FindObjectOfType <MainUIPanel>().GetComponent <RectTransform>(); mainUIPanelImage = mainUIPanel.GetComponent <Image>(); mainUIPanelImage.raycastTarget = false; // add callback to main ui panel, so when we click on it it close the settingspanel EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener((eventData) => { CloseSettingsPanel(); }); mainUIPanelEventTrigger = mainUIPanel.GetComponent <EventTrigger>(); if (mainUIPanelEventTrigger == null) // We don't have an eventtrigger on it so add one { mainUIPanelEventTrigger = mainUIPanel.gameObject.AddComponent <EventTrigger>(); } mainUIPanelEventTrigger.triggers.Add(entry); mainUIPanelEventTrigger.enabled = false; bool panelInstantiated = false; for (int i = 0; i < changePanels.Length; i++) { if (changePanels[i].screenName == to) { // We already have the one we needed to instantiated if (currentChangePanel == i) { break; } InstantiateChangePanel(changePanels[i]); panelInstantiated = true; break; } } // If we found no screens in changePanels instantiate the very first element if (!panelInstantiated) // We already have it instatiated { InstantiateChangePanel(changePanels[0]); } SettingsButton sB = FindObjectOfType <SettingsButton>(); if (sB != null) // We have no button -> no setup of button needed { settingsButton = sB.GetComponent <Button>(); settingsButton.onClick.AddListener(() => { ToggleSettingsPanel(); }); } }