- Home /
Question by
jimmyismike · Aug 03, 2012 at 05:06 PM ·
guifov
GUI Script Help
So I got this script (thank you MrDiablo) but I keep getting errors. Can anyone tell me whats wrong?
var GUIon:boolean;
function Update(){
//Checks to see if you've pressed the M key and if GUIon = true or false. if it's false it opens the GUI and turns it off if it's on(this is needed because otherwise the gui is open all the time)
if(Input.GetButtonDown("M") && !GUIon){
GUIon = true;
}else if(Input.GetButtonDown("M") && GUIon){
GUIon = false;
}
}
//Shows everything when GUIon = true;
function OnGUI(){
if(GUIon){
GUI.Box (Rect (X pos,Y pos,X size,Y size), "FOV");
if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 70")) {
camera.fieldOfView = 70;
}
if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 80")) {
camera.fieldOfView = 80;
}
if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 90")) {
camera.fieldOfView = 90;
}
}
}
Comment
What is the error? also you can already simplify the first part with:
var GUIon:boolean;
function Start(){
GUIon = false;
}
function Update(){
if(Input.GetButtonDown("$$anonymous$$"))GUIon=!GUIon;
}
Best Answer
Answer by fafase · Aug 03, 2012 at 05:15 PM
I think you are missing the reference to the camera:
var GUIon:boolean;
function Start(){
GUIon = false;
}
function Update(){
if(Input.GetButtonDown("M"))GUIon=!GUIon;
}
function OnGUI(){
if(GUIon){
GUI.Box (Rect (X pos,Y pos,X size,Y size), "FOV");
if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 70")) {
Camera.main.fieldOfView = 70;
}else if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 80")) {
Camera.main.fieldOfView = 80;
}else if (GUI.Button (Rect (X pos,Y pos,X size,Y size), "FOV = 90")) {
Camera.main.fieldOfView = 90;
}
}
}
Also, you can use else if in the OnGui as you would not press two button at the same time.
Are your errors like X undeclared variable, pos undeclared variable, Y undeclared variable and so on?
$$anonymous$$ore of these BCE0044: expecting ), found 'pos'.
Did you copy paste my script? If so, you should maybe think of giving value to all those X pos, Y pos...