Unity Volume Slider value cast to text problem

Updated on October 27, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on October 27, 2017

So I have a volume slider that works with a min value of 0 and max of 1.
I have it setup so the slider shows it’s current value in a text element using ToString.
The problem I’m having is I can’t figure out how to show the value on a 0-100 scale when the slider is on a 0-1 scale.
If I change the slider max value to 100 and enable whole numbers, the volume still only works from 0-1.
I’m trying to figure out how to get the slider to show the text value as an int 0-100 instead of a float value.


Here you can see the slider working on a 0-1 scale with the float value, I want this to work but with the text on a 0-100 scale.


Here is how I want the text to be displayed but the slider doesn’t work past 1.


Here is how I’ve tried to get it to work, I’ve Googled this extensively and this is something rudimentary I’ve tried to come up with, I know I could probably do this a better way but at the moment I’m still not that good with Unity C#


public Slider musicSlider;
public Slider buttonSlider;
public Text musicSoundValue;
public Text buttonSoundValue;
// Update is called once per frame
void Update ()
float musicValue = musicSlider.value;
float buttonValue = buttonSlider.value;
//Casts the float value to an int
int musicSound = (int)musicValue;
int buttonSound = (int)buttonValue;
musicSoundValue.text = ("");
buttonSoundValue.text = ("");
musicSoundValue.text = musicSlider.value.ToString ("");
buttonSoundValue.text = buttonSlider.value.ToString ("");
  • Liked by
1 on October 27, 2017

You can just multiply you slider value to get the results.


int value = musicSlider.value * 100;

musicSoundValue.text = value.ToString();

on October 27, 2017

Thanks I’ll give that a try, kind of expected it to be something simple XD

Show more replies
  • Liked by