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
0
Question by LuckyLuke · Aug 29, 2012 at 09:00 PM · onguicallnotcalling

OnGUI is not being called

I was attempting to create a main menu, and after inputting a 3D Options Menu, OnGUI refused to be called, I suspected this when my fade-in code stopped working, however the exact same code in another level worked perfectly, it fades in and fades out. To test if OnGUI was actually being called I added a small Label to test it. It was not renderered.

 function OnGUI(){
 
     //Debugging OnGUI (Because evidence inclines it's not being called)
     GUILayout.BeginArea(Rect(10,10,200,20));
     GUILayout.Label("OnGUI is being called");
     GUILayout.EndArea();    
     
     if(firstLoad){
         fadeTime = 2;
         alphaFadeValue -= Mathf.Clamp01(Time.deltaTime / fadeTime);
         
         GUI.color = Color(0,0,0,alphaFadeValue);
         GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height),fadeTexture);
         
         if(alphaFadeValue <= 0){
             firstLoad = false;
             fadeTime = 0;
             alphaFadeValue = 0;
         }
     }
     
     if(isLoading){
         fadeTime = 2;
         alphaFadeValue += Mathf.Clamp01(Time.deltaTime / fadeTime);
         
         GUI.color = Color(0,0,0,alphaFadeValue);
         GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height),fadeTexture);
         
         if(alphaFadeValue >= 1){
             fadeTime = 0;
             alphaFadeValue = 1;
             Application.LoadLevel("Level1");
         }
 
     }
         
 }

As you can see, the very first bit of code should be working, but it does not show up. It was working fine up until now.

Code i'm using for attempting to start a new game;

 var CameraObject : Transform;
 
 function OnMouseDown() {
     
     var MenuOptions = CameraObject.GetComponent(MainCamera);
     
     MenuOptions.isLoading = true;
 
 }

I know that it's working because the 'isLoading' boolean is turned to true, as I can see in the Inspector, however the OnGUI function is not being called.

Comment
Add comment · Show 3
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 nicloay · Aug 30, 2012 at 07:49 AM 0
Share

why do you assign isLoading as true, looks like you need to initialize firstLoad variable

avatar image LuckyLuke · Aug 30, 2012 at 07:55 AM 0
Share

firstLoad is called when the document is first loaded, so basically when the game is first loaded, it does a fade in, isLoading is for when the 'Start Game' button is clicked, because I wanted the GUI to be handled here in one script I created a Boolean that could be accessed by other scripts.

avatar image OperationDogBird · Aug 30, 2012 at 08:43 AM 1
Share

Have you done a simple Debug.Log inside of OnGUI just to be sure some other scipt isnt setting that boolean to false right away.

 function OnGUI()
 {
     Debug.Log("OnGUI is being called");
 }

Another thought i had, is this inside of a custom class? If it is in a class that does not extend $$anonymous$$onoBehaviour OnGUI will never be called.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by prototype7 · Aug 30, 2012 at 09:51 AM

Try start a new Game with

 var isLoading : false;
 
 function OnMouseDown() {
     if(!isLoading){
     //  ...load your Menu
     }else{
     //    ...unload your Menu
     }
     isLoading = !isLoading;
 }
Comment
Add comment · Show 1 · 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 prototype7 · Aug 31, 2012 at 12:43 AM 0
Share

thanks man.

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

10 People are following this question.

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

Related Questions

C# - How do I increase the variable from another script? 2 Answers

RPC call failed 1 Answer

calling functions help {javascript} 1 Answer

Game responds slow to device event 0 Answers

Call a function once from OnGUI 2 Answers


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