The question is answered, right answer was accepted
How do I display AudioMixer volume as a percentage
I want to display the percentage value of my Slider in a text alongside. I have tried many formula's and did a lot of searching but the main problem is the AudioMixer value is Min -80 to Max 0, not 0 to 1.
Here is an example of one formula that works when the slider is 0 to 1:
sliderPercent.text = (Mathf.RoundToInt (Volume * 100)) + "%";
Any ideas? Thanks
Answer by TreyH · May 20, 2018 at 02:16 AM
It's the same idea, your range is -80 to 0 and you want that to be 0 to 100. Add 80 and multiply it by 5/4.
Wow, I was so close. I was trying to $$anonymous$$ultiply by .8 ins$$anonymous$$d of 1.25. Works great. Thanks TreyH
@RayDart converted so that this can be marked as closed.
Answer by HalitKLYC · May 25, 2018 at 06:22 PM
Firstly , in your slider set your min value to 0.001 and max value to 1 then go to script and do that:
lets say : myParam = your Parameter in audio mixer.
then go to your script and :
public Text yourText;
public AudioMixer yourMixer;
public void DisplayAudio(float Volume)
{
mixer.SetFloat("myParam",Mathf.Log(Volume)*20);
yourText.text = Mathf.FloorToInt(Volume * 100) + "%";
}
then add this script to your Canvas or Background whatever you want then add your Mixer and Text and that's it.
Thanks for your solution. I have already use the solution from TreyH and it worked fine also. I couldn' find a way to show that i accepted his answer.
Follow this Question
Related Questions
UI Text created from C# Script 0 Answers
Cant find text objects after being renamed. 1 Answer
How to assign Text of a Panel child via Script on Panel 0 Answers
UI Text Not Updating 1 Answer
Changing the UI Text 0 Answers