- Home /
GUIButtons Follow different GameObjects??
i want to make that 4 GUIButtons Follow different GameObjects each, i mean GUIButon1 follow GameObject1, GUIButon2 follow GameObject2.
I have just one GUIButton that follows one GameObject. (cube1), but i can't make multiples GUIButtons to different GameObject. i have this. please help..
public GameObject cube1;
public GameObject cube2;
public GameObject cube3;
public GameObject cube4;
public GameObject cube5;
void OnGUI()
{
Vector3 V = Camera.main.WorldToScreenPoint(cube1.transform.position);
if (GUI.Button(new Rect(V.x,Screen.height - V.y,300,200),"cube1"))
}
Answer by WestonD · Feb 27, 2013 at 12:58 AM
Im new to unity, but you might try adding the objects to an array and iterating through it.
public GameObject cube1;
public GameObject cube2;
public GameObject cube3;
public GameObject cube4;
public GameObject cube5;
var objectArray =[cube1,cube2,cube3,cube4,cube5];
void OnGUI()
{
for(i=0,i=5,i++){
Vector3 V = Camera.main.WorldToScreenPoint(objectArray[i].transform.position);
if (GUI.Button(new Rect(V.x,Screen.height - V.y,300,200),"cube1"))
}
}
did work either, ive being trying different things but nothing.
Check the other POST for my updated answer. This is just a copy of what I placed there but the other has the updated answer for C# and a request for the error log output for the error you mentioned.
Your answer
Follow this Question
Related Questions
how to reference GameObjects to GUIButton??? 1 Answer
Correcting Object Offset on WorldToScreenPoint 0 Answers
How to make an object fixed on the screen? 1 Answer
Find transform.position of Another Game Object 1 Answer
Continually Updating position of Instantiated Object (to Mouse Pointer) 0 Answers