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 elnawe · Nov 22, 2011 at 03:55 AM · guiguitexture

Why GUI doesn't appear?

Hi. First of all, I'm new with Unity.

I have a problem with GUI, sometimes appears but, in other projects, doesn't.

I used a code in a Tutorial for draw a Crosshair in the middle of screen, the code is:

 var position : Rect;
 var crosshairTexture : Texture2D;
 
 function Start() {
     position = Rect((Screen.width - crosshairTexture.width)/2, (Screen.height - crosshairTexture.height)/2, crosshairTexture.width, crosshairTexture.height);
 }
 
 function onGUI() {
     GUI.DrawTexture(position, crosshairTexture);
 }

I was doing other projects myself but, before I make my first game with Unity I wanted read some Tutorials and documentation. I was doing the FPS tutorial and when a I write the code the GUI Crosshair doesn't appears in screen. I attachs that script on a Empty GameObject called GUI.

I'm doing something bad? (GUI.Label doesn't appears too)

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

1 Reply

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

Answer by Default117 · Nov 22, 2011 at 05:44 AM

First ensure that you are actually assigning a texture to crosshairTexture, make it a public variable so that it will be exposed in the inspector and drag a texture onto it.

Comment
Add comment · Show 3 · 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 elnawe · Nov 22, 2011 at 06:00 AM 0
Share

Thanks, but I think in JS all variables are publics except you write private before. I found the answer, my problem are the spaces. After a "(" I have to press spacebar. I write again the code with spaces after all sentences and works fine. Problem Result.

How can I mark this like solved?

EDIT: Think I found it.

avatar image Default117 · Nov 22, 2011 at 06:08 AM 0
Share

Really? Didn't think that that would have been the issue! Oh well, glad it works now! As for the automatic public variables, i wasn't sure if it was C# or JS which makes them public automatically, so i just provided that anyway =P

avatar image CHPedersen · Nov 22, 2011 at 07:55 AM 0
Share

It's not about spaces after parentheses. The reason nothing was getting drawn before probably had more to do with OnGUI being with a capital O. ;) $$anonymous$$onoBehavior doesn't have a function called onGUI, as you can see:

http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.OnGUI.html

$$anonymous$$aybe you ended up correcting that at the same time as the parenthesis+space-thing, and it looked like the space had fixed it?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer

Move GUI elements. 0 Answers

GUITexture Button? 1 Answer

GUI Transparency Changing automatically 2 Answers

Write a Shader for GUI (GUITexture or scripted GUI) 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