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 patben8 · Aug 21, 2012 at 10:06 PM · guivar

How can i link a var to a gui?

Hi i need to know how to use a variable in a script and copy that variable in a gui script. In other words i need to know how i can link the var to a gui text.

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

2 Replies

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

Answer by OperationDogBird · Aug 21, 2012 at 10:59 PM

You would reference that variable in the line for the string.

SomeScript

 public var valueVariable:float;

GUIScript

 private var someScript:SomeScript;
 
 function Start()
 {
     someScript=transform.GetComponent(SomeScript);
 }
 function OnGUI()
 {
     GUI.Label(rect,someScript.valueVariable.ToString("f2"));
 }
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 patben8 · Aug 24, 2012 at 03:10 PM 0
Share

Thanks but it says: $$anonymous$$ identifier `f2´ How can i fix that and what does it mean

avatar image Bunny83 · Aug 24, 2012 at 03:13 PM 0
Share

He ment .ToString("f2")

You can even omit the format string and just use .ToString()

 GUI.Label(rect,someScript.valueVariable.ToString());
avatar image OperationDogBird · Aug 24, 2012 at 04:07 PM 0
Share

Sorry bout that, forgot the quotes. Thanks @Bunny83 for correcting that.

@patben8 The "f2" format makes the output string display 2 characters past the decimal rather than the entire value. Its useful if you display float values and only want the short version. "1.25621" will be displayed as "1.25". You could also use "f1" to display 1 digit past the decimal. If it is an int, it will add a decimal and 0's. With "f1" "3000" becomes "3000.0"

avatar image
0

Answer by patben8 · Aug 24, 2012 at 05:33 PM

ok thanks but it gives me this

BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(System.Type, String)' was found.

OH And thanks so much for the help guys!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning two variables ? 1 Answer

GUI after pressed Destruction 2 Answers

Two variables in a GUI Button? 1 Answer

GUI.TextField problem, won't update var. 0 Answers

Using for ... var ... in loop to access variable. 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