• 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
Question by Ecnalyr · May 24, 2010 at 04:53 AM · scoreonguigui.labelbce0023bce0022

I'm having trouble getting my score to display through GUI.Label

When I run the following script:

static var SCORE : int = 0;

function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), SCORE); }

I get this error: Assets/MeMadeStuff/ScoreBoard.js(5,19): BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(UnityEngine.Rect, int)' was found.

And my score of 0 does not display.

I do not understand why I cannot display SCORE, when I change the script to read:

static var SCORE : int = 0;

function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "hello"); }

The script properly displays "hello"

What am I doing wrong that is preventing me from being able to have my static var SCORE displayed on my screen?

Comment

People who like this

0 Show 0
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

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by Eric5h5 · May 24, 2010 at 05:07 AM

If you look at the docs for GUI.Label, you see this:

static function Label (position : Rect, text : string) : void
static function Label (position : Rect, image : Texture) : void
static function Label (position : Rect, content : GUIContent) : void

(Plus another version of the same with a GUIStyle parameter.) As you can see, you can only display a string, a texture, or GUIContent. In order to display an int, you have to convert it to a string, such as with ToString().

Comment

People who like this

0 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 Ecnalyr · May 24, 2010 at 05:58 AM 0
Share

Thanks for the tip. So I'm now trying to convert my integer SCORE to a string. I read here http://answers.unity3d.com/questions/9679/score-system-for-destroying-objects , that you do that by using the following command:

SCORE.ToString();

but when I do that, I get the error:

Assets/MeMadeStuff/ScoreBoard.js(8,16): BCE0022: Cannot convert 'int' to 'String'.

My int SCORE is set to 0, so shouldn't this have no problem changing the integer 0 to the string 0? I've got to be missing something here. . .

avatar image Eric5h5 · May 24, 2010 at 06:43 AM 1
Share

@Ecnalyr: Are you using "`function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), SCORE.ToString()); }`" ?

avatar image Ecnalyr · May 25, 2010 at 12:01 AM 0
Share

I thought I was using just that, but when I deleted mine and pasted yours, it worked. Maybe there was a weird typo I wasn't aware of. Thank you sincerely.

avatar image

Answer by oz m · May 24, 2010 at 10:27 AM

I did a label with ints in it without having to use toString() before. Maybe it's because for the text parameter of Label i put something like "int : " + myInt

Comment

People who like this

0 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 Mike 3 · May 24, 2010 at 11:09 AM 0
Share

if you do string + int, it implicitly casts the int to a string to do the concatenation - if you only use an int, you need to do it yourself with ToString()

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

GUI.Label font change ? 2 Answers

Can't draw GUI.Label text on subpixel values 0 Answers

Problem instantiating a prefab with static typing 1 Answer

score broken, score loads on new scene but then errors 0 Answers

Updating GUI.Label for Score 5 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