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 arturoza · Aug 21, 2014 at 03:46 PM · onguivoidongui error

OnGui not working (again)

Hi, me again, I can't make a Gui work, here's my script, I've tried with both "OnGUI" and "OnGui" and I can't get it work. Am I doing something wrong??!!

I started a new project, and attached my c# script to my camera, it didn't work, I tried with empty objects and nothing, I also tried with Button, Text , and also Nothing!!

 public class Example : MonoBehaviour {
 
     void OnGui () 
     {
         GUI.Label (new Rect (10, 10, 100, 20), "Hello World!");
     }
 }

 public class Example : MonoBehaviour {
 
     void OnGUI () 
     {
         GUI.Label (new Rect (10, 10, 100, 20), "Hello World!");
     }
 }
 
 

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by jokim · Aug 21, 2014 at 04:07 PM

First off, the right syntax is the second one : OnGUI

Other than that, everything seems ok... now, not to sound rude or anything, but here's a few things that might prevent it from working :

  • Is your script file named "Example.cs" ?

  • Did you save the script ?

  • Did you hit play ?

I actually copied the code and ran, it works fine.

Comment
Add comment · Show 5 · 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 arturoza · Aug 21, 2014 at 04:48 PM 0
Share

yep, yep and yep, I have worked with scripts but never with OnGUI, which is new for me

avatar image jokim · Aug 21, 2014 at 05:21 PM 0
Share

Another thing i forgot to mention, but it's probably already there, seeing as you can use GUI...

Did you include the right namespaces ?

 using UnityEngine;
 using System.Collections;


And, When you say "it doesn't work"

What exactly happens ? Do you have errors in the console ? or it runs without showing texts ?

Try adding this in the OnGUI method :

 Debug.Log("Test");

and see if the console shows something

avatar image arturoza · Aug 21, 2014 at 08:24 PM 0
Share

Hi, yes I include:

using UnityEngine; using System.Collections;

and I don't have errors, runs normally but doesn't show the text

it's weird because I started a new project, did the same thing and I still can't see the text.

avatar image jokim · Aug 22, 2014 at 02:15 PM 0
Share

Indeed, this is weird, I started a new project, made a single script, called Example, copied your code... and it's working on my side...

I even reverted layouts to factory settings, i didn't change my $$anonymous$$ain camera, it's the one that comes from a new Scene... back drop is blue, text is white...

I have no idea what's going wrong on your side... Back-up your projects and Reinstall ?

avatar image arturoza · Aug 23, 2014 at 03:02 AM 0
Share

I was almost sure it wasn't something I was doing, I reinstalled Unity and it worked again, I don't know why or how, but now it work. thanks for your help.

avatar image
0

Answer by armada29 · Apr 24, 2016 at 07:35 AM

hi. is it too late? i had same problem and figured out it's because of lighting problem. first off, check the window -> lighting setting. then just the skybox set to None. if you may see the gui, then solve just lighting problem.

Comment
Add comment · 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
0

Answer by Jason-King · Oct 15, 2016 at 12:34 AM

Another reason that the OnGUI could appear to not be working is if you changed the Game's Free Aspect Scale to a large enough value that the text is simply off the camera view. Yes, it can be that simple.

Comment
Add comment · Show 2 · 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 Bunny83 · Oct 15, 2016 at 05:03 AM 0
Share

But that can't be the case here since a Debug.Log statement inside OnGUI should fire at least two times each frame. Since it doesn't there's a different problem. The most common ones would be:

  • The script isn't attached to any gameobject in the scene.

  • The script is disabled in the inspector

  • The gameobject or any parent gameobject is deactivated in the inspector.

avatar image rlneumiller Bunny83 · Jul 01, 2021 at 03:24 AM 0
Share

5 years later and your comment helped me get past this issue after starting over twice (neglected to attach script to the gameobject).

avatar image
0

Answer by mini-lucy · Jun 26, 2017 at 03:14 AM

Would you try to tap the "2D" button in the Scene? I'm the beginner of Unity coding but It seems it matters that it is 3d or 2d.

Comment
Add comment · 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

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

28 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI script giving weird error 1 Answer

EditorGUILayout.Foldout not working properly - results in argument exceptions 1 Answer

OnGUI() not showing anything 2 Answers

OnGUI button changes size for resolution, but text doesnt? 1 Answer

How to make a GUI window appear on clicking a game object 0 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