- Home /
GUI.Box and Camera Movement
Hello, below is my piece of code from different objects put together for the ease of understanding my problem. I have a GUI.Button that appears when certain gameobjects are selected and the camera updates its transform.position according to the transform.position of the gameobject selected. When the GUI.Button is clicked the camera updates its transform.position to an alltogether different position and there needs to be a GUI.Box that is 2/3 of the screen width and full screen height. The camera updates its position correctly when the GUI.Button is pressed but the GUI.Box does not appear on the screen.
var camera:gameobject;
camera=GameObject.Find("Main Camera");
function OnGUI()
{
if (GUI.Button (Rect(Screen.width/2-140,Screen.height-40,50,40),"Build"))
{
camera.transform.position=Vector3(0,9,-28);
camera.transform.eulerAngles=Vector3(0,0,0);
GUI.Box(Rect(0,0,Screen.width*2/3,Screen.height),"Build Options");
}
}
Answer by robertbu · Jun 28, 2013 at 03:41 PM
The GUI.Button() statement will only be true for a single frame, so you GUI.Box is being displayed...for a single frame. I'm not sure how you want to handle the logic, but you can do something like:
function OnGUI()
{
if (GUI.Button (Rect(Screen.width/2-140,Screen.height-40,50,40),"Build"))
{
camera.transform.position=Vector3(0,9,-28);
camera.transform.eulerAngles=Vector3(0,0,0);
buildOptions = true;
}
if (buildOptions)
GUI.Box(Rect(0,0,Screen.width*2/3,Screen.height),"Build Options");
}
Where bildOptions is declared at the top of the file with an initial value of false.
It appears that my problem resulted from a not properly configured IF statement and I have solved it. Also you are correct in saying that there needs to be a boolean variable so that GUI.Box can stay more than one frame. Thank you
Your answer
![](https://koobas.hobune.stream/wayback/20220613105043im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to stop the player rotation after i stop the camera? 1 Answer
ROBLOX Like Camera Script 2 Answers
Smooth camera on moving platform 1 Answer
How to make camera zooming with a range? [C#] 0 Answers
Third Person Camera 1 Answer