Solid video! I think the only one missing detail that would be nice to mention for people who aren't familiar with the log function, would be that it doesn't support zero :P. In other words. If your volume slider hits zero, log(0) is undefined (or negative infinity). But at that point you just want the resulting DB to be -80, since that is the lowest value that is shown in the mixer editor. In my code, I actually had a "if zero" check, that would just set the result to -144. But I did find a better way that would make more sence, because really what is needed is a "noise floor". So the code would look like: max( 19.9316*log( linearVolume ), -80 ) And I used "19.9316" instead of 20 because apparently that is also closer to the specific decibel values like 0.5 = -6 db
I am so happy I finely found the "right" way to do this. I have seriously been struggling for a long while now trying to get the slider to control volume in my project. My partner doesn't even know it's done yet. I will invite her in and make her cry now (as I am) :) THANK YOU!! side not: RU-vid is a B, why couldn't this video come up a long time ago? Thank again!
Thanks for another informative tutorial. Very helpful. Just wanted to note that: ValueText.SetText($"{Value.ToString("N4")""); can be simplified to: ValueText.SetText($"{Value:N4}"); Since C# string interpolation is just syntactic sugar for String.Format and will automatically convert numeric values to string if enclosed in {}, and allows for declaring formatting after the : so no need to call ToString(). Thanks agian for the awesome content.
Hey thanks man! Such great timing. I just started working on the audio for my game yesterday and it's been all new territory for me. Super grateful that you coincidentally uploaded this around the same time haha. I appreciate the time and energy you put into sharing your knowledge. It's a whole separate skill knowing all these things And being able to present them in an informative and easy to follow way. Cheers
AudioSource.volume = Slider.value is okay if you have very few AudioSources and/or you do not need to worry about varying levels of volume of individual AudioSources! Especially for simple games with only 1 or 2 AudioSources you can totally do that. This solution is much more robust in allowing you to create dynamic soundscapes by adjusting each individual AudioSource volume based on the clip(s) they'll play and have the entire game's volume adjusted in a consistent way when you have many AudioSources.
How can I change the n4 parameters to match a percent based whole number? (going from 100% to 0% on slider text while maintaining the audio source to go from 1 down to 0.0000)
@@LlamAcademy The problem with that is if I change the slider value to min 0, max 100, it only adjusts the audio mixer to go from 1 to 0 once the slider reaches either 1 or 0. How can I adjust the text to change from saying 1 to saying 100 as any values I adjust in script doesnt change the text value from 1. And if for some reason it does, the audio mixer will only recognize the text value between 0-1 with 4 decimal places. So if I used slider.value * 100 where would I place that to overwrite the ``` ValueText.SetText($"{Value.ToString("N4")}"); ``` ? And how do I incorporate a % symbol?
@@LlamAcademy I figured it out. had to change ``` ValueText.SetText($"{Value.ToString(N4)}"); ``` to ``` ValueText.text = Mathf.RoundToInt(Value * 100f) + "%"; ``` So that it would not only add a % symbol but also show value of 100 to 0 in whole numbers while still adjusting the audio volume from 1 to 0 in fractional numbers.
one thing tho, this is assuming the maximum value of the volume is 0 and minimum is -80. what if we want the maximum value to be lower than 0? is there any change to the script then?
0->-80 is a pretty standard range used for perception of audio, but if you want to clamp the values lower than 0 I would recommend setting up another AudioMixerGroup setting the max value to be -10 or whatever you want the maximum to be.
Hello, I am trying to troubleshoot what seemingly should be a simple problem, but unfortunately I definitely didn't structure my scripts properly. It involves player skins, and addressables. What defines a local reference in unity? I asked a more in depth question elsewhere, and I was essentially told that all my local references would break, and then was told if it was prefab references they "should" break. I believe it was a typo and he meant wouldn't break. Thank you for any help!
@@LlamAcademy “Hello, I am trying to finish my mobile game. I could really use some help and I'm not quite sure where to go besides RU-vid and different forums. I would be forever grateful if you can even halfway steer me in the right direction. I am getting into addressables to deal with player skins. However I am wondering if I've engaged in some bad coding practices that will force me to kind of recode pretty much my whole PlayerController. Or I guess migrate it over to the GameManager. I have a PlayerController script and a GameManager script as standard. In my PlayerController script I have included stuff like the fuel bar, tracking when the engine should shut off due to lack of fuel, adding fuel, audio sources, particles, etc. As of right now I am creating each of the different skins to store as prefabs w/ particles and sound to call as the addressable. I have no idea how it will interact with calling a prefab that includes a player controller script. How will the public audio sources react upon being called. Will I have to move all of these things over to the GameManager script? Or do I need to make them private and initialize them in the start method? I am backing up my file daily because I feel like I'm one click away from a catastrophic failure lol. I really appreciate any and all help! EDIT: To try to consolidate, I understand the difference between public and private variables. I just dont have any idea how fundamentally a script reacts upon getting called. If I create the game object essentially, and initialize all the public variables then create a prefab of that game object. Will I get a bunch of null reference exceptions when that object is loaded. Or will it react more so how I imagine/assume and it will be created as it was copied.” Small comment thread from this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-HlwVj_2S6rw.html