- Home /
Question by
Wikened · Dec 21, 2011 at 07:27 PM ·
guigameobjectnetworkingbuttontag
Searching for gameobjects with a tag and creating a button for each one?
How do you search for GameObjects with tags and then add their names to a button?
Comment
Answer by karl_ · Dec 21, 2011 at 09:41 PM
A quick example.
void Start()
{
GameObject[] go = GameObject.FindGameObjectsWithTag("tag");
}
void OnGUI()
{
foreach(GameObject g in go)
{
if(GUILayout.Button(g.name))
{
DoSomething(g.name);
}
}
}
void DoSomething(string buttonName)
{
switch(buttonName)
{
case "Blue":
Debug.Log("The 'Blue' button was pressed");
break
case "Red":
Debug.Log("The 'Red' button was pressed");
break
}
}
Your answer
Follow this Question
Related Questions
GameObject.Find only working on server? 1 Answer
Detect Click on Gameobject 0 Answers
How do I make individual buttons change individual variables? 0 Answers
Cube click pop-up menu 0 Answers
Networking and UI Buttons 1 Answer