- Home /
How to create an object with buttons and image attached?
I want to press on a button and create a prefab game object on which i attach an image and buttons. This is my code so far:
public GameObject prefab;
private GameObject myprop;
`void OnGUI(){
...`
if (GUILayout.Button("Propose")){
myprop=Instantiate(prefab,new Vector3(Screen.width/2,Screen.height/2,0) , Quaternion.identity)as GameObject;}
myprop GameObject has the following script where i create image and button
void OnGUI(){
GUILayout.BeginArea(new Rect(250,250,150,170));
GUILayout.BeginVertical();
GUILayout.Box (propIcon);
if(GUILayout.Button("ok")){
//do something
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
i cannot see the prefab object on scene and also attached image and buttons dont appear attached on object but on other location. Does anyone know how to make this happen? Thank you in advance.
Comment
Your answer

Follow this Question
Related Questions
GUI.Button on MouseHover 1 Answer
On Click paramaters disappear from button prefab? 5 Answers
A Problem with button listener in Start() 0 Answers
Auto-sizing colliders upon creation. 1 Answer
Multiple button draws 1 Answer