Тёмный

Audio/Volume Slider in Unity Done RIGHT | Unity Tutorial 

LlamAcademy
Подписаться 23 тыс.
Просмотров 9 тыс.
50% 1

Опубликовано:

 

10 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 26   
@Andrew90046zero
@Andrew90046zero Год назад
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
@LlamAcademy
@LlamAcademy Год назад
This is great information. Thank you for sharing!
@recodegamesstudio
@recodegamesstudio 2 месяца назад
thanks for pointing out, I set my slider minimum value to 0.0000001 etc and it works
@TkMe2Mrz
@TkMe2Mrz Год назад
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!
@MQNGameDev
@MQNGameDev 2 года назад
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.
@LlamAcademy
@LlamAcademy 2 года назад
Thanks! I didn't know that! I'll definitely start using the shorthand format!
@iancherabier5920
@iancherabier5920 11 месяцев назад
Really cool tutorial, learned quite a bit about managing volume in unity. Thanks a lot!
@Josh-gb9ml
@Josh-gb9ml 2 года назад
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
@LlamAcademy
@LlamAcademy 2 года назад
🙏 thank you for your kind words. I appreciate that!
@Golden_games
@Golden_games 2 года назад
I use audio source.volume to be equal to slider value but this is an interesting method
@LlamAcademy
@LlamAcademy 2 года назад
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.
@Golden_games
@Golden_games 2 года назад
@@LlamAcademy thanks for the explanation..
@bitbottoken7777
@bitbottoken7777 2 года назад
Fantastic, thanks!
@dreamisover9813
@dreamisover9813 2 года назад
Great one, thanks!
@psychoknight9208
@psychoknight9208 9 месяцев назад
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
@LlamAcademy 9 месяцев назад
I think for the display you can do something like slider.value * 100 and show with however many decimals you would like.
@psychoknight9208
@psychoknight9208 9 месяцев назад
@@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?
@psychoknight9208
@psychoknight9208 9 месяцев назад
@@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.
@dewakeadilan
@dewakeadilan Год назад
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?
@LlamAcademy
@LlamAcademy Год назад
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.
@alperaydin7011
@alperaydin7011 2 года назад
Thanks
@LlamAcademy
@LlamAcademy 2 года назад
You're welcome!
@TheNbc27
@TheNbc27 2 года назад
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
@LlamAcademy 2 года назад
Could you send me the link to the more in-depth question so I can get more context about this question?
@TheNbc27
@TheNbc27 2 года назад
@@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
@evgenkonyshock4913
@evgenkonyshock4913 Год назад
this ux is so unity
Далее
A small kitten was dumped #cat #kitten #cutecat
00:41
🔊 Всё про звук в Unity3D [Tutorial]
21:31
How to  make pause menu in Unity and Playmaker
16:08
Просмотров 9 тыс.
Canvas Scaler, Explained | Unity Tutorial
13:24
Просмотров 30 тыс.
Unity AUDIO Volume Settings Menu Tutorial
9:24
Просмотров 64 тыс.