Hi guys! I have a tutorial on how to add an On/Off Sound Button! Do check it out if you would like to add an On/Off Sound Button instead of a Volume Slider! ua-cam.com/video/AFcHsKd_aMo/v-deo.html
Hi i have a problem when i made my SoundManager script just like you did it gived me an error in unity saying : 'PlayerPrefs' does not contain a definition for 'Haskey' please help me
to all the lazy people there is a copy! using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SoundManager : MonoBehaviour { [SerializeField] Slider volumeSlider // Start is called before the first frame update void Start() { if (!PlayerPrefs.HasKey("musicVolume")) { PlayerPrefs.SetFloat("musicVolume", 1); Load(); } else { Load(); } } public void ChangeVolume() { AudioListener.volume = volumeSlider.Value; Save(); } private void Load() { volumeSlider.value = PlayerPrefs.GetFloat("musicVolume"); } private void Save() { PlayerPrefs.SetFloat("musicVolume", volumeSlider.value); }
Thx but you made a mistake. You wrote value big at the start at line 26. And you forgot an semicolon at [SerializeField] Slider volumeSlider;. But still thx
i fix it for u, you well come using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ValumManager1 : MonoBehaviour { [SerializeField] Slider volumeSlider; // Start is called before the first frame update void Start() { if (!PlayerPrefs.HasKey("musicVolume")) { PlayerPrefs.SetFloat("musicVolume", 1); Load(); } else { Load(); } } public void ChangeVolume() { AudioListener.volume = volumeSlider.value; Save(); } private void Load() { volumeSlider.value = PlayerPrefs.GetFloat("musicVolume"); } private void Save() { PlayerPrefs.SetFloat("musicVolume", volumeSlider.value); } }
The tutorial is pretty clear. Though the SoundManager wouldn't become active if the slider itself is disabled, if this is going to be used for a Settings menu. Other than that, thanks for the help!
If anyone down the road wants to get around this, you can simply place the script on a different game object that won't be hidden at the start. in my case, i just popped it on my canvas in both my main menu and game scenes. the audio settings carried over between scenes just fine. if you move the script, be sure to link the volume slider in the script and put the object with the script in the On Value Changed function on the slider as shown in the video, otherwise the slider won't be connected to listener's volume.
I wanna Clap for you Man.... You did not only tell how to handle game volume but also to save data later on..... That's amazing thank you for your effort.
Really cool. Only think is when slider does not load on the very begining, but untill we use options menu, since does not load saved volume until then.
Don't know if you still around. But two basic questions. How do I add a separate slider not effected by the music/volume such as for sound effects, and how do I combine this with the mute option so when game starts, even though mute is off, slider isn't itself set to zero value? I think under the load and save you have to place one in an if and else statement but I am not sure how to do so correctly. Many thanks if you do respond.
[SerializeField] Slider volumeSlider; this code got an error for me Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name 'Slider' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\Ryzen 5\New Unity Project (4)\Assets\SoundManager.cs 8 Active
Nope for me it is working correctly even after exiting the game and loading it again. I guess you guys are messing up with the start function and the load function
I know this was a long time ago, but for those like me who had the same problem: I forgot the "!" at the start of the Start function if(!PlayerPrefs....etc) Also another problem I faced, in case others have the same issue: When I loaded my main menu back up, the volume would be reset, and then when I clicked the "Options" button, which brought up the options menu (in which we have the volume slider), THEN the music would adjust. I think this was happening because when you first load the main menu, the options menu is disabled, meaning the volume management script is also disabled, until you click the options button. I fixed this by making an empty game object OUTSIDE of the options menu, and using that in the reference for the Inspector instead. Hope this helps some other newbies like me :)
It only saves when i press the settings button, however when i start the game and am on the main menu it hasnt saved, i have to press the settings menu for it to save
so I have an issue where my volume slider is on a screen in the pause menu that isnt active in unity until I press the right buttons to see the screen. my Saved audio level isnt loaded until I click the buttons and see that screen. any ideas how to make the audio save load without having to open that screen?
Hi i have a problem when i made my SoundManager script just like you did it gived me an error in unity saying : 'PlayerPrefs' does not contain a definition for 'Haskey' please help me
What a great video! It helped me a lot! However, just wondering, do you know how to manage also a slider for Sound Effects? For example, if the player only wants to hear the background music so they can reduce the volume of SFX and viceversa. Anyways, awesome video!
Great job but I couldn't get it to work (I probably got something wrong with the code). Could you publish the code or script in C to import it and study it directly in Unity?
Hey, thanks for the great tutorial. Although I would like to imply that I get the "NullReferenceException: Object reference not set to an instance of an object" on my script in the "private void Load"
hey so i got the same problem and the solution with me was that i set the Min Value and Max Value on the Slider to difference things, if you put Min Value 0 and Max Value 1 it worked for me....
Hello, how can I do to delimit an area so that the player can, for example, swim only in the space where there is water (following the mouse) and when it reaches the surface of the water, stop following the mouse and gravity is applied to it
Your tutorial is amazing, not only changing the volume, but also saving it, is perfect fot me... but... this is the third tutorial that won't work :( the slider's "on value changed" option isn't showing any audio option, just "Mono Script - String Name"
Hi guys! I have a tutorial on how to add an On/Off Sound Button! Do check it out if you would like to add an On/Off Sound Button instead of a Volume Slider! ua-cam.com/video/AFcHsKd_aMo/v-deo.html
Plz one video for unity touch inputs
And what is your email??
Hi i have a problem when i made my SoundManager script just like you did it gived me an error in unity saying : 'PlayerPrefs' does not contain a definition for 'Haskey' please help me
thank you very much, youre the first person who teached me this after i tryed it by Brackeys and some other guys
keep it up!
to all the lazy people there is a copy!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SoundManager : MonoBehaviour
{
[SerializeField] Slider volumeSlider
// Start is called before the first frame update
void Start()
{
if (!PlayerPrefs.HasKey("musicVolume"))
{
PlayerPrefs.SetFloat("musicVolume", 1);
Load();
}
else
{
Load();
}
}
public void ChangeVolume()
{
AudioListener.volume = volumeSlider.Value;
Save();
}
private void Load()
{
volumeSlider.value = PlayerPrefs.GetFloat("musicVolume");
}
private void Save()
{
PlayerPrefs.SetFloat("musicVolume", volumeSlider.value);
}
Thx but you made a mistake. You wrote value big at the start at line 26. And you forgot an semicolon at [SerializeField] Slider volumeSlider;. But still thx
i fix it for u, you well come
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ValumManager1 : MonoBehaviour
{
[SerializeField]
Slider volumeSlider;
// Start is called before the first frame update
void Start()
{
if (!PlayerPrefs.HasKey("musicVolume"))
{
PlayerPrefs.SetFloat("musicVolume", 1);
Load();
}
else
{
Load();
}
}
public void ChangeVolume()
{
AudioListener.volume = volumeSlider.value;
Save();
}
private void Load()
{
volumeSlider.value = PlayerPrefs.GetFloat("musicVolume");
}
private void Save()
{
PlayerPrefs.SetFloat("musicVolume", volumeSlider.value);
}
}
The tutorial is pretty clear. Though the SoundManager wouldn't become active if the slider itself is disabled, if this is going to be used for a Settings menu.
Other than that, thanks for the help!
If anyone down the road wants to get around this, you can simply place the script on a different game object that won't be hidden at the start. in my case, i just popped it on my canvas in both my main menu and game scenes. the audio settings carried over between scenes just fine.
if you move the script, be sure to link the volume slider in the script and put the object with the script in the On Value Changed function on the slider as shown in the video, otherwise the slider won't be connected to listener's volume.
dude thank you so much. great tutorial. simple. informative but still quick and to the point. please do many many more :)
it was very simple and way better than other videos out there
I wanna Clap for you Man.... You did not only tell how to handle game volume but also to save data later on..... That's amazing thank you for your effort.
Bro, thank you so much, I spent so many hours on this and I was about to lose my mind, I love you.
Holy man! Even though I am not a native English speaker, I can understand everything thanks dude!
bawal aadmi ho yaar yahi to mai kab se dhood raha tha
channel ko full support
Really cool. Only think is when slider does not load on the very begining, but untill we use options menu, since does not load saved volume until then.
You saved my life with that if in the Start function, awesome tutorial!!
Awesome tutorial m8, quite handy for a junior game developer as myself who recently got involved into Unity. Thanks for sharing this :)
Thank you man i did have to change the "value" function part of the code but other than that it compleatly worked for me
I love how when you're getting into unity and you are just like yup... Yup.. and done
wanted a simple volume slider tutorial, upon hearing that accent i had to check where you're from
a fellow singaporean :D
Don't know if you still around. But two basic questions. How do I add a separate slider not effected by the music/volume such as for sound effects, and how do I combine this with the mute option so when game starts, even though mute is off, slider isn't itself set to zero value? I think under the load and save you have to place one in an if and else statement but I am not sure how to do so correctly. Many thanks if you do respond.
Thank you so much, I have tried 3 systems and this is the only one that works, nice work
[SerializeField] Slider volumeSlider;
this code got an error for me
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name 'Slider' could not be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\Ryzen 5\New Unity Project (4)\Assets\SoundManager.cs 8 Active
using UnityEngine.UI; write this ontop
I hate to rewrite code, make a typo every time! You should paste them somewhere so that we can copy them. Thanks anyway, it works.
Thanks mah friendo for the tips. The default value returns though once you exit the game.
Same
Nope for me it is working correctly even after exiting the game and loading it again. I guess you guys are messing up with the start function and the load function
I know this was a long time ago, but for those like me who had the same problem:
I forgot the "!" at the start of the Start function
if(!PlayerPrefs....etc)
Also another problem I faced, in case others have the same issue:
When I loaded my main menu back up, the volume would be reset, and then when I clicked the "Options" button, which brought up the options menu (in which we have the volume slider), THEN the music would adjust.
I think this was happening because when you first load the main menu, the options menu is disabled, meaning the volume management script is also disabled, until you click the options button.
I fixed this by making an empty game object OUTSIDE of the options menu, and using that in the reference for the Inspector instead.
Hope this helps some other newbies like me :)
@@caidenmacgregor3271 wow ur the best this help me alot i was wondering why i had the same issues too
i put this on my setting screen, how do you make it load on the start screen as well?
this video helped me so much with my assignment for college! thank you :)
It only saves when i press the settings button, however when i start the game and am on the main menu it hasnt saved, i have to press the settings menu for it to save
omg thank you so much just what i needed!!!
Its so awesome. Worked first try.
so I have an issue where my volume slider is on a screen in the pause menu that isnt active in unity until I press the right buttons to see the screen. my Saved audio level isnt loaded until I click the buttons and see that screen. any ideas how to make the audio save load without having to open that screen?
Same
You really explained it so good, I loved it. But for some reason my slider resets every time I quit and restart.
It is probabbly something to do with the player save data in the script double check that your is the same as his😀😀
Hi i have a problem when i made my SoundManager script just like you did it gived me an error in unity saying : 'PlayerPrefs' does not contain a definition for 'Haskey' please help me
I also get the same thing, if anyone know how to solve it please tell me.
is the K in key capitalized? it should be
@@F1R3BOLT13 yes the K should be capital
Whenever I restart my game the volume resets to 1 but the slider is where I set it last time. What is happening?
Great video! Thanks for the tutorial keep uploading more videos :)
Thanks a lot this video was very helpful and you did a very good job at explaining it.
Thanks mate, love it!
thank you very helpful would recommend 5 stars
what about the sfx along with music how to add another slider
dude, you have the same voice as the Excel Budget Template i watched. Is that also you!?
Great! Straight to the point.
Thank you for a great video ! I'm already subscriber and waiting for your next great upload video ;-)
What a great video! It helped me a lot! However, just wondering, do you know how to manage also a slider for Sound Effects? For example, if the player only wants to hear the background music so they can reduce the volume of SFX and viceversa.
Anyways, awesome video!
It requires more code. like you need to seperate the audios for sound effects and the background music.
Thank you, simple and good explanation.
I've implemented this, and the saving works, but the volume doesn't actually change when playing :/
very nice tutorial! thank you
Bro Im building a cannom game wher cannon follows the mouse to aim I want to add a slider for android controls please help
THANK YOUUUUU amazing tutorial
you are the best!!! thank youuuuu
Great job but I couldn't get it to work (I probably got something wrong with the code). Could you publish the code or script in C to import it and study it directly in Unity?
Thanks! Help so much. Easy Explanation
Awesome video thanks!
You are best guy that I watched in youtube thanks thanks
Brilliant!! Is there a way to isolate just the music volume, not the entire game?
Great lesson, thanks.
Hey, thanks for the great tutorial. Although I would like to imply that I get the "NullReferenceException: Object reference not set to an instance of an object" on my script in the "private void Load"
Did you try
private void Load()
@@ythedemon8742 i have the same problem and i have the () at the end, no idea what causes the error message
copy and paste here the script so i can help you
hey so i got the same problem and the solution with me was that i set the Min Value and Max Value on the Slider to difference things, if you put Min Value 0 and Max Value 1 it worked for me....
Almost 1 years have been passed since you faced the problem, I think you have solved it. So I am not going to give you any solution, hehehe
Nice and precise tutorial. Many thanks.
How can i do this with arrow keys or + and -?
nice tutorial worked first try and i understand the code
Thanks for the tutorial
Great Video !!
Hello, how can I do to delimit an area so that the player can, for example, swim only in the space where there is water (following the mouse) and when it reaches the surface of the water, stop following the mouse and gravity is applied to it
use trigger function with the animation :)
really good, helped me alot, keep it up bro
how to do this with audio mixer?
Thank you very much man.
Best sscripter thanks so much:3
Awesome tutorial! Thank you!
very helpful really thank u
Thank you a lot, very nice video and turorial keep it up
thats awesome it helps me a lot thank you for all of your awesome usefull videos
Really Great Tutorial
Просто в шоке, очень простой скрипт и всё работает, как часы, лучшее видео.
i must be dumb bc it doesnt work. i cant attach the script bc it tells me it cant have a script. wtf bruh
Have you tried making a slider in Unity's new UI Toolkit? I found it *a* *lot* harder to customize and am curious if you came to the same conclusion.
Thank You So Much! You are a Legend! :D
Man it's awesome!
this works for all audio, right?
tysm hooson
Thank you so much
A heart by hooson is a dream!
Thank You for this. Well Done! :D
Thank you very much, bro you helped me a lot.
I Like ur way teach
plz make more video tutorials
Great!! Thanks a lot!
Your tutorial is amazing, not only changing the volume, but also saving it, is perfect fot me... but... this is the third tutorial that won't work :( the slider's "on value changed" option isn't showing any audio option, just "Mono Script - String Name"
try creating an empty object and put the script there. Use that empty object the same way as how the script was used in the video
ur the goat thanks
Nice as always
thanks you so much you are amazing
NICE. thanks
why does mine doesnt save :(( pls help
awesome tutorial
Even with this tutorial youtube couldn’t make a volume slider for their MUSIC app
Thank you very much my friend
Great video.
Thank you :-)
Hey bro one video for unity touch inputs plz plz plz plz plz plz
Thanks a lot.
Thanks❤
Thanks a lot
I like video and thank u very much
Thank you!
Thank you so much
very good