- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
CYVISUALEFFECTS · May 23, 2013 at 01:58 PM ·
audiojavasource
How to decrease audio source's volume using script?
In my script, these two lines:
var newAlpha : float = 1.0 - (health / startingHealth);
staticRenderer.material.color.a = newAlpha;
change the alpha of a material. I need to add another 2 lines like these, which will change the volume of an audio source. Any ideas?
Comment
Answer by Stormizin · May 23, 2013 at 02:06 PM
Try this:
var newAlpha : float = 1.0 - (health / startingHealth);
staticRenderer.material.color.a = newAlpha;
audio.volume = newAlpha;
Edit: You need to alternate between 0.0f and 1.0f in audio.volume see this Audio Volume for more information
Your answer
![](https://koobas.hobune.stream/wayback/20220613102801im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Audio source not playing 7 Answers
How to Create Separate Volumes 1 Answer
Audio Sources and Listeners low sound volume problem 1 Answer
AudioSource.PlayClipAtPoint loop ? 2 Answers
Pause screen audio setup 1 Answer