- Home /
Calling functions from OnGUI
I am working on an editor database system and I want to have some buttons across the top that show the different types of items to can be created and added to the asset database. The functionality is there, but for whatever reason, I cannot call any functions from buttons in OnGUI. What am I missing?
void OnGUI()
{
EditorGUILayout.Space();
MakeNewWeapon(); This will work
if(GUILayout.Button("Weapons"))
{
MakeNewWeapon(); This will not.
}
EditorGUILayout.EndHorizontal();
}
void MakeNewweapon() { code goes here... }
The function name in the line
$$anonymous$$akeNewWeapon();
in your OnGUI function, and the line
void $$anonymous$$akeNewweapon() { code goes here... }
don't match; One uses a capital "W" for "Weapon, the otehr a lowercase "w" for "weapon". $$anonymous$$aybe this is the problem? Otherwise, have you tried inserting Debug.Log lines to see if all parts of your code are reached? Also, what's with the EditorGUILayout.EndHorizontal() line at the end of your sample code? I assume you forgot to delete it when inserting your code snippet, so I'm aksing :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How do I create buttons dynamically in OnGui? 1 Answer
Distribute terrain in zones 3 Answers
Trouble detecting button release with Input.GetButtonUp() 1 Answer
Animation not working 1 Answer