Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AdamEstone · Aug 15, 2011 at 07:19 PM · stringfloatintconvertmultiply

GUI.Label shows volume from a slider

why can't i do this

 var hSliderValue2:float;
 
 function Update(){AudioListener.volume=hSliderValue2;}
 function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), hSliderValue2*10 .ToString());
 hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}
 

I want to have a GUI.Label there will display 5 if the hSliderValue2 = 0.5

Comment
Add comment · Show 6
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 illwunn · Aug 15, 2011 at 07:30 PM 0
Share

what is the error?

avatar image AdamEstone · Aug 15, 2011 at 07:33 PM 0
Share

The GUI.Label shows 10, if the hSliderValue2 = 1.

avatar image illwunn · Aug 15, 2011 at 07:38 PM 0
Share

im a bit confused, isnt that what you want?

avatar image AdamEstone · Aug 15, 2011 at 07:46 PM 0
Share

"I want to have a GUI.Label there will display 5 if the hSliderValue2 = 0.5"

avatar image illwunn · Aug 15, 2011 at 07:50 PM 0
Share

is the problem that its displaying 5.32131239ish number, and you want it to display a solid 5 number?

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
-1
Best Answer

Answer by illwunn · Aug 15, 2011 at 08:52 PM

try using this:

 var hSliderValue2:float;

 var hsliderFullNumber:float;

 function OnGUI () {
     hsliderFullNumber= Mathf.Round(hSliderValue2*10);
     GUI.Box (Rect (10, 10, 100, 30), hsliderFullNumber.ToString());
     hSliderValue2 = GUI.HorizontalSlider (Rect (10, 500, 160, 30), hSliderValue2, 0, 1);
 }
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 AdamEstone · Aug 15, 2011 at 09:02 PM 0
Share

DUDE, i'm almost crying now of happiness! IT WOR$$anonymous$$S 100%! ;D

avatar image illwunn · Aug 15, 2011 at 09:18 PM 0
Share

hehe nice, glad to help =)

avatar image Rennat · Aug 15, 2011 at 09:37 PM 0
Share

3 answers? There is an EDIT button for revisions and new info.

avatar image
-1

Answer by illwunn · Aug 15, 2011 at 08:06 PM

well if thats the case then, you will just have to cast your output value into an int instead of a float to get a solid number.

try (int)hSliderValue2*10 .ToString(); or (hSliderValue2*10 as int) .ToString();

i usually use c# so im not too familiar with javascript syntax

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 AdamEstone · Aug 15, 2011 at 08:35 PM 0
Share

did NOT work in the java script: BCE0044: expecting ), found 'hSliderValue2'.

avatar image
-1

Answer by illwunn · Aug 15, 2011 at 08:19 PM

 var hSliderValue2:float;

 function Update(){AudioListener.volume=hSliderValue2;}
 function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), (int)hSliderValue2*10 .ToString());
 hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}

 var hSliderValue2:float;

 function Update(){AudioListener.volume=hSliderValue2;}
 function OnGUI () {GUI.Label (Rect (1000, 475, 100, 30), (hSliderValue2*10 as int).ToString());
 hSliderValue2 = GUI.HorizontalSlider (Rect (1000, 500, 160, 30), hSliderValue2, 0, 1);}

Try either one of those, see how i replaced the content parameter in the GUI.label, try that and see if it outputs a solid number

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 AdamEstone · Aug 15, 2011 at 08:32 PM 0
Share

2 erros: BCE0044: expecting ), found 'hSliderValue2'. BCE0043: Unexpected token: ).

at the first script. and the next one: BCE0006: 'int' is a value type. The 'as' operator can only be used with reference types.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Convert Text to float 3 Answers

Download a WWW int? Or convert? 1 Answer

convert string to int 0 Answers

c# convert int to string 2 Answers

Convert int to string 2 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