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

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
Add comment · 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 : $$anonymous$$onoBehaviour {
     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
1
Best Answer

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

Your error says that Rect is expecting a float but it got something different. The compiler think 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 thinks 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
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
2

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 this:


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
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 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.

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

Gui label variable as a string.. 1 Answer

Tracking Down GUI Errors 0 Answers

Can't use any GUI functions 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