- Home /
On off game objects
**I'm trying to create a script for turning gameObjects on and off. I want it when I touch on the first button another 2 buttons will appear to select what design of the object they want to put. for example on first button it is named as BED, then when you click BED there will be two buttons that will appear named blue bed and red bed, for example blue bed is clicked the blue bed will be activated. and when red bed, the red bed will be shown.
here in my code when i Click on first button another button will appear but the function in the second button is already executed when the first button is click:**
bool toggle = false; public GameObject targetItem;
void Start(){
targetItem.SetActive (false);
}
void OnGUI (){
if (Input.GetKeyDown(KeyCode.Escape)){
//Camera.mainCamera.backgroundColor = Color.red;
Application.LoadLevel(6);
}
if (GUI.Button (new Rect (150, 420, 100, 50), "Sofa")) {
toggle=!toggle;
}
if (toggle)
{
if (GUI.Button (new Rect (150, 350, 100, 50), "Sofa"))
;
{
targetItem.SetActive(true);
}
} } }
Answer by robertbu · Feb 27, 2014 at 06:44 PM
Sometimes fixes are simple. Remove the ';' on line 17. You are terminating your if statement with this ';'.
Thank you sir! :) it works! thanks a lot :) God bless.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Change button opacity using C# script? 1 Answer
Using a GUI.Button to load next 'screen'? Also, textfields 0 Answers
A node in a childnode? 1 Answer