- Home /
change prefabs with Gui.buttons
i have a problem with my script i can't replace the prefab, this script no destroy the others prefabs and show a prefabs on other
MENU WITH BUTTONS
[cube ] [sphere]
[plane ] [capsule]
this the script:
var thePrefab1: GameObject; var thePrefab2: GameObject; var thePrefab3: GameObject; var thePrefab4: GameObject;
function OnGUI () { // Make a background box GUI.Box (Rect (10,10,190,130), "MENU WITH BUTTONS ");
// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed
if (GUI.Button (Rect (20,40,80,20), "Cube")) {
var instance1 : GameObject = Instantiate(thePrefab1, transform.position, transform.rotation);
}
// Make the second button.
if (GUI.Button (Rect (110,40,80,20), "Sphere")) { var instance2 : GameObject = Instantiate(thePrefab2, transform.position, transform.rotation);
}
// Make the third button.
if (GUI.Button (Rect (20,90,80,20), "Capsule")) {
var instance3 : GameObject = Instantiate(thePrefab3, transform.position, transform.rotation);
}
// Make the second button.
if (GUI.Button (Rect (110,90,80,20), "cylinder")) {
var instacne4 : GameObject = Instantiate(thePrefab4, transform.position, transform.rotation);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612191857im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Managing gui with prefabs 2 Answers
How to apply check on an instanced prefab 2 Answers
GUI button texture different color when script is on Instantiated object 0 Answers
Checking if object intersects? 1 Answer
Instantiating Prefab Every 5 seconds 1 Answer