Hey guys, I’m a fairly new programmer and unity user, this is my first post (because I can’t find an answer for it in google!).
I’m making a GUI builder that uses ExecuteInEdit mode. My code takes some parameters from the user, and when you click the public bool in the inspector it acts as a button and makes a window for the user. The problem I’m having is that when I create this window in the edit mode, the buttons do not work. They don’t function at all. However, if I go into play mode, back to the inspector, and create the window, the buttons work perfectly, as long as I’m in play mode. This doesn’t really do any good for me because the window needs to be made in edit mode, the user won’t have the ability to create the menu while ingame.
The problem lies somewhere with being in edit mode or play mode.
Any thoughts for the newbie?
Thanks!
Code below, if it helps:
This is my code that makes the buttons and adds the listener
List<GameObject> tabs = new List<GameObject>();
for(int i = 0; i<tabList.Count;i++)
{
int index = i;
GameObject tab = (GameObject) Instantiate(btnPrefab);
Button tabButton = tab.AddComponent<Button>();
tabs.Add (tab);
tab.transform.SetParent(tabFrame.transform);
tab.name = "Tab " + index;
tab.GetComponent<Image>().color=Color.yellow;
tab.GetComponentInChildren<Text>().text = tabList[index];
RectTransform tabRect = tab.GetComponent<RectTransform>();
tabRect.sizeDelta = new Vector2(tabFrameRect.rect.width, 20);
tabRect.localPosition = new Vector3(0,tabFrameRect.rect.height/2-tabRect.rect.height/2-20*index,0);
tabButton.onClick.RemoveAllListeners();
tabButton.onClick.AddListener(() => DisableToggleTest(tabContentFrames,tabContentFrames[index],tabs,tabs[index])); //IMPORTANT NOTE! YOU CANNOT USE INT I IN ANY WAY SHAPE OR FORM FOR ADD LISTENER!
//tabButton.onClick.AddListener(delegate{DisableToggle(tabContentFrames,tabContentFrames[index]);}); //IMPORTANT NOTE! YOU CANNOT USE INT I IN ANY WAY SHAPE OR FORM FOR ADD LISTENER!
DisableToggleTest(tabContentFrames,tabContentFrames[0],tabs,tabs[0]);
}
This is the method being passed to the listener
void DisableToggleTest(List<GameObject> goList,GameObject go, List<GameObject> btnList, GameObject btn)
{
foreach(GameObject goTemp in goList)
{
goTemp.SetActive(false);
}
foreach(GameObject tempButton in btnList)
{
tempButton.GetComponent<Image>().color = Color.grey;
}
btn.GetComponent<Image>().color = Color.white;
go.SetActive(true);
}