Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
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
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Aug 03, 2012 at 05:10 PM 0
Share

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;
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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.

Comment
Add comment · Show 10 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jimmyismike · Aug 03, 2012 at 05:22 PM 0
Share

This still gives me like 18 errors

avatar image fafase · Aug 03, 2012 at 06:02 PM 0
Share

Are your errors like X undeclared variable, pos undeclared variable, Y undeclared variable and so on?

avatar image jimmyismike · Aug 03, 2012 at 06:08 PM 0
Share

$$anonymous$$ore of these BCE0044: expecting ), found 'pos'.

avatar image fafase · Aug 03, 2012 at 06:20 PM 0
Share

Did you copy paste my script? If so, you should maybe think of giving value to all those X pos, Y pos...

avatar image jimmyismike · Aug 03, 2012 at 06:23 PM 0
Share

Still have 18 errors.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Null reference exception[SOLVED] 1 Answer

Error with multiplayer script (not done) 1 Answer

GUI Button not working...but the the script is correct... 2 Answers

(4.6 UI) How to set up a window with x buttons, with a scroll bar? 1 Answer

Scrolling Text 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges