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 Matthew 5 · Mar 28, 2011 at 05:37 AM · guitextvariablestringlabel

GUI text label using variable values and text

Hey all, just a quickie.

i have a score collector that 'collects' through out each level scores, achievements etc.

it is stored until the last scene were the GUI will display all this;

my questions is how do i make my labels or text display and do math functions, like... you see: "5 power ups X 100 points = 500"

var Collector: GameObject;

function Start () { Collector = GameObject.Find("Collector"); }

And on the function OnGui i'd like to do this;

GUI.Label (Rect (10, 10, 100, 20), "Tackled '+tackledamount' X DO MULTIPLY by 100 = "answer" ");

... yeh that looks terrible.. but i want it to end up on screen as;

"Tackled X times 100 points = X"

... and the values i want to grab from the script "Collector"... so i dont know how to take those value and use them in this GUI script or how to do the math on them on the gui?

Matty

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 Jake-L · Mar 28, 2011 at 10:05 AM

Use the right syntax and it should work as you want it:

GUI.Label(Rect(10,10,100,20),"Tackled "+Collector.TackledAmount+" times  100 points = "+Collector.TackledAmount*100);
Comment
Add comment · Show 5 · 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 Matthew 5 · Mar 28, 2011 at 10:31 PM 0
Share

thanks for your help, i didnt know the syntax to use, so thank you for showing me.

I tried the code... i get "Collector is not a member of Unity.GameObject" .. i change the variable to Object... i get a huge load of Boo errors...

What am i ment to set the variable as?

$$anonymous$$atty

avatar image Jason B · Mar 29, 2011 at 01:07 AM 0
Share

You made your assignment wrong. If you just do "Collector = ..." then it assumes that Collector is some sort of member of Unity script. You need to do something like "GameObject collector = ..." and it will work.

avatar image Matthew 5 · Mar 31, 2011 at 12:41 AM 0
Share

I don't understand.. The variable is stated as a GameObject, Collector being its name, then in the Start function it assigns it as such, thats all fine... I have found a new problem though, Collector is the GameObject, Tackled amount isnt a component.. so it would need to be Collector.Collector.TackledAmount... ??? what!?

avatar image Jake-L · Mar 31, 2011 at 06:11 AM 0
Share

I just corrected your syntax in the GUI.Label call. TackledAmount and any other variable you declare can't be part of an gameobject. They must be declared inside a component that you attach to a gameobject, I thought that was obvious. So you'll need to find your script using GameObject.Find("Collector").GetComponent("$$anonymous$$yCollectorClass");

avatar image Matthew 5 · Apr 06, 2011 at 06:36 AM 0
Share

my issue was a spelling mistake... laugh at me please. All of your ideas would have worked fine... i'm ashamed. Thanks everyone, glad to close this question.

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

No one has followed this question yet.

Related Questions

Optimizing OnGUI 1 Answer

OnGUI called after LateUpdate screwing up debug text database 1 Answer

IF in a GUI 2 Answers

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

Inputfield set as 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