• 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 GeoDoX · Sep 09, 2013 at 02:03 AM · errorguilabel

Errors when adding a GUI.Label C#

I'm not sure what I'm doing wrong here. For the String parameter I have also tried with a .ToString on both calls.

 GUI.Label( new Rect(Screen.width/2, Screen.height*0.2, 150, 50), "$" + Money);
 GUI.Label( new Rect(Screen.width*0.1, Screen.height*0.2, 150, 50), Depth + " ft.");

Any help on solving what I'm doing wrong would be greatly appreciated! Here are my variables used.

 int Money = 50;
 int Depth = 0;

I would really like to keep the variables int's as well. Here are the error's.

error CS1502: The best overloaded method match for UnityEngine.Rect.Rect(float, float, float, float)' has some invalid arguments error CS1503: Argument #2' cannot convert double' expression to type float'

error CS1502: The best overloaded method match for UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid arguments error CS1503: Argument #1' cannot convert object' expression to type UnityEngine.Rect'

error CS1502: The best overloaded method match for UnityEngine.Rect.Rect(float, float, float, float)' has some invalid arguments error CS1503: Argument #1' cannot convert double' expression to type float'

error CS1502: The best overloaded method match for UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid arguments error CS1503: Argument #1' cannot convert object' expression to type UnityEngine.Rect'

Comment

People who like this

0 Show 2
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 Jonathon82931 · Sep 09, 2013 at 02:44 AM 0
Share

I ran into that a bit ago here is the code I was working on hope it helps you solve your problem. using UnityEngine; using System.Collections;

 public class RPGplayerstats : MonoBehaviour {
     public float curHP = 37;
     public int maxHP = 37;
     public float curEP = 30;
     public int maxEP = 30;
     public int capEXP = 150;
     public int curEXP = 0;
     public int Level = 1;
     public int DPS = 3;
 
     void OnGUI () {
         GUI.Box(new Rect (5, 5, Screen.width / 5 / (maxHP / curHP), 20), curHP + "/" + maxHP);
         GUI.Box(new Rect (5, 15, Screen.width / 5 / (maxEP / curEP), 20), curEP + "/" + maxEP);
         GUI.Box(new Rect (5, 30, Screen.width / 5 / (capEXP / curEXP), 20), curEXP + "/" + capEXP);
     }
     void update (){    
         if(curEXP >= capEXP)
         {
             Level = Level + 1;
         }
         if(curHP < 0){
             curHP = 0;
         }
         if(curHP > maxHP){
             curHP = maxHP;
         }
         if(curEP < 0){
             curEP = 0;
         }
         if(curEP > maxEP){
             curEP = maxEP;
         }
     }
 }
 

I ran into the problem when I tried to display the current level

avatar image Jonathon82931 · Sep 09, 2013 at 02:46 AM 0
Share

I also don't know what screen.height will do for you but that might be causing you problems. I really don't know much about gui

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by perchik · Sep 09, 2013 at 02:42 AM

Your error says that Rect is expecting a float but it got somet$$anonymous$$ng different. The compiler t$$anonymous$$nk you're passing in double numbers instead of float. Basically there are different size decimal numbers in the computer...

For all of your decimal numbers, you need to use an f on the end like 0.2f . When you type 0.2 the compiler t$$anonymous$$nks its a double, but rect takes in floats.

 GUI.Label( new Rect(Screen.width/2, Screen.height*0.2f, 150, 50), "$" + Money);
 GUI.Label( new Rect(Screen.width*0.1, Screen.height*0.2f, 150, 50), Depth + " ft.");
Comment
syclamoth

People who like this

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

Answer by ZouBi27 · Sep 09, 2013 at 03:06 AM

As the error says, you need float as parameters, not double. To put a float value, you need to add 'f' at the end of the number.

  1. double

  • 1.0f float

Try t$$anonymous$$s:


GUI.Label( new Rect(Screen.width/2f, Screen.height*0.2f, 150f, 50f), "$" + Money);
GUI.Label( new Rect(Screen.width*0.1f, Screen.height*0.2f, 150f, 50f), Depth + " ft.");
Comment
syclamoth
Fattie

People who like this

2 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 ZouBi27 · Sep 09, 2013 at 08:51 AM 0
Share

sorry, perchik was faster.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

GUI Text Blinking came up with one error. 3 Answers

Translating from game space to view space 2 Answers

Web player GUI only appears on fullscreen? 0 Answers

JavaScript OnGUI GuiSkins aren't working, multiple scripts 1 Answer

Gui label variable as a string.. 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