Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active September 16, 2015 21:22
Show Gist options
  • Save unitycoder/812f7e0729683ea889d1 to your computer and use it in GitHub Desktop.
Save unitycoder/812f7e0729683ea889d1 to your computer and use it in GitHub Desktop.
Call function if OnGUI() dropdown item was selected
// vars
string[] optionList = new string[] {"Apples", "Oranges", "Androids"};
int index = 0;
// loop
void OnGUI()
{
GUI.changed = false; // not needed if EditorGUILayout.Popup is first in OnGUI
index = EditorGUILayout.Popup("My List",index, optionList);
if (GUI.changed) DoSomething(); // NOTE: gets also called if same item is selected from list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment