x


FOV Change With GUI

Hey I'm bad with GUI so could someone help me out, I need a script where you could press M and a GUI menu would open. You would have 3 options 70FOV 80FOV and 90FOV then to close it press M again. As I said I'm not good with GUI but I would still like you to explain what everything in the script is and what it does if that's not to much to ask. Help me get a better idea of how GUI works. Thanks -jimmyismike

more ▼

asked Aug 03 '12 at 04:53 AM

jimmyismike gravatar image

jimmyismike
1.8k 34 49 63

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Im not the best at GUI so someone will probably come up with a better way to do it lol.

(JavaScript)

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; 

}

}

}

This requires you to change some things to fit your project but should work otherwise

more ▼

answered Aug 03 '12 at 06:21 AM

MrDiab1o gravatar image

MrDiab1o
35 1 1 6

Im getting some errors (11,2): BCE0044: expecting }, found 'else'. And (17,1): BCE0044: expecting EOF, found '}'.

Aug 03 '12 at 06:49 AM jimmyismike

Try adding or erasing a } at the end

Aug 03 '12 at 06:51 AM Radon

Didn't work

Aug 03 '12 at 06:56 AM jimmyismike

Here is your error. Make sure that every { has an end at some point like this }. So if you have 5 { for example, you must have 5 } as well. Otherwise your function wouldn't have an end.

Aug 03 '12 at 07:00 AM Radon

Everytime I fix one error I cause 10 more. can you test it out in your unity and see if you can tell me whats wrong?

Aug 03 '12 at 07:05 AM jimmyismike
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5059
x3673
x379
x59

asked: Aug 03 '12 at 04:53 AM

Seen: 329 times

Last Updated: Aug 03 '12 at 05:03 PM