How To Make A Volume Slider In 4 Minutes - Easy Unity Tutorial

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ • 164

  • @hoosontech
    @hoosontech  3 роки тому +13

    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

    • @arehman9529
      @arehman9529 3 роки тому

      Plz one video for unity touch inputs

    • @arehman9529
      @arehman9529 3 роки тому

      And what is your email??

    • @kingstar9995
      @kingstar9995 3 роки тому

      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

  • @danuvip
    @danuvip 3 роки тому +10

    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!

  • @J-Raxx
    @J-Raxx 2 роки тому +27

    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);
    }

    • @derechtemidnaplays
      @derechtemidnaplays 2 роки тому +2

      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

    • @Lofimusic-e6k
      @Lofimusic-e6k 12 днів тому

      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);
      }
      }

  • @a.giovanni.m6740
    @a.giovanni.m6740 6 місяців тому +1

    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!

    • @hazyrays994
      @hazyrays994 13 днів тому +1

      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.

  • @BlackIce420
    @BlackIce420 2 роки тому +8

    dude thank you so much. great tutorial. simple. informative but still quick and to the point. please do many many more :)

  • @clashface
    @clashface Рік тому +1

    it was very simple and way better than other videos out there

  • @hafsasheikh9511
    @hafsasheikh9511 3 роки тому

    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.

  • @mlsanica7618
    @mlsanica7618 2 роки тому

    Bro, thank you so much, I spent so many hours on this and I was about to lose my mind, I love you.

  • @sorryseori471
    @sorryseori471 2 роки тому

    Holy man! Even though I am not a native English speaker, I can understand everything thanks dude!

  • @alliswell8826
    @alliswell8826 3 роки тому

    bawal aadmi ho yaar yahi to mai kab se dhood raha tha
    channel ko full support

  • @fleshandblood5392
    @fleshandblood5392 3 роки тому +1

    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.

  • @byMariusz
    @byMariusz 3 роки тому

    You saved my life with that if in the Start function, awesome tutorial!!

  • @nightwingzero8905
    @nightwingzero8905 3 роки тому +1

    Awesome tutorial m8, quite handy for a junior game developer as myself who recently got involved into Unity. Thanks for sharing this :)

  • @hoimenam5381
    @hoimenam5381 10 місяців тому

    Thank you man i did have to change the "value" function part of the code but other than that it compleatly worked for me

  • @kierangalvin3732
    @kierangalvin3732 8 місяців тому

    I love how when you're getting into unity and you are just like yup... Yup.. and done

  • @nofacegamedev
    @nofacegamedev Рік тому

    wanted a simple volume slider tutorial, upon hearing that accent i had to check where you're from
    a fellow singaporean :D

  • @druwayu
    @druwayu Рік тому +1

    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.

  • @jerocrackh
    @jerocrackh 3 роки тому +1

    Thank you so much, I have tried 3 systems and this is the only one that works, nice work

  • @deathnote3283
    @deathnote3283 3 роки тому +2

    [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

    • @shadbicky
      @shadbicky 2 роки тому

      using UnityEngine.UI; write this ontop

  • @llYuki0okami
    @llYuki0okami 2 роки тому

    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.

  • @StroberriBS
    @StroberriBS 3 роки тому +3

    Thanks mah friendo for the tips. The default value returns though once you exit the game.

    • @ThePigLord
      @ThePigLord 3 роки тому

      Same

    • @its_prince4real
      @its_prince4real 2 роки тому

      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

    • @caidenmacgregor3271
      @caidenmacgregor3271 2 роки тому +3

      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 :)

    • @princenwachukwu9084
      @princenwachukwu9084 Рік тому +1

      @@caidenmacgregor3271 wow ur the best this help me alot i was wondering why i had the same issues too

  • @noodles4s892
    @noodles4s892 Рік тому

    i put this on my setting screen, how do you make it load on the start screen as well?

  • @ckdotdotdot
    @ckdotdotdot 2 роки тому

    this video helped me so much with my assignment for college! thank you :)

  • @lordwigstyle8017
    @lordwigstyle8017 Рік тому

    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

  • @personinaplace7087
    @personinaplace7087 2 роки тому +1

    omg thank you so much just what i needed!!!

  • @AbdullahBRashid
    @AbdullahBRashid Рік тому

    Its so awesome. Worked first try.

  • @jordynthompson7619
    @jordynthompson7619 3 роки тому +1

    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?

  • @LolupkeGaming_yt
    @LolupkeGaming_yt 2 роки тому +1

    You really explained it so good, I loved it. But for some reason my slider resets every time I quit and restart.

    • @Dan_perks
      @Dan_perks 2 роки тому

      It is probabbly something to do with the player save data in the script double check that your is the same as his😀😀

  • @kingstar9995
    @kingstar9995 3 роки тому +1

    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

    • @myratyra2721
      @myratyra2721 2 роки тому

      I also get the same thing, if anyone know how to solve it please tell me.

    • @F1R3BOLT13
      @F1R3BOLT13 2 роки тому

      is the K in key capitalized? it should be

    • @shadbicky
      @shadbicky 2 роки тому

      @@F1R3BOLT13 yes the K should be capital

  • @TokenYT
    @TokenYT 10 місяців тому

    Whenever I restart my game the volume resets to 1 but the slider is where I set it last time. What is happening?

  • @strizeeygames9216
    @strizeeygames9216 3 роки тому +1

    Great video! Thanks for the tutorial keep uploading more videos :)

  • @saeko2212
    @saeko2212 2 роки тому +1

    Thanks a lot this video was very helpful and you did a very good job at explaining it.

  • @peyn8
    @peyn8 Рік тому

    Thanks mate, love it!

  • @suaisojohnricg.2098
    @suaisojohnricg.2098 10 місяців тому +1

    thank you very helpful would recommend 5 stars

  • @aslinoobdev
    @aslinoobdev 2 роки тому

    what about the sfx along with music how to add another slider

  • @andrewhill7073
    @andrewhill7073 14 днів тому

    dude, you have the same voice as the Excel Budget Template i watched. Is that also you!?

  • @manishdhakal9379
    @manishdhakal9379 Рік тому

    Great! Straight to the point.

  • @iiqehc
    @iiqehc 2 роки тому

    Thank you for a great video ! I'm already subscriber and waiting for your next great upload video ;-)

  • @gabrielulate
    @gabrielulate 3 роки тому +7

    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!

    • @StroberriBS
      @StroberriBS 3 роки тому

      It requires more code. like you need to seperate the audios for sound effects and the background music.

  • @ardae53
    @ardae53 3 роки тому +2

    Thank you, simple and good explanation.

  • @sephn1x
    @sephn1x 9 місяців тому

    I've implemented this, and the saving works, but the volume doesn't actually change when playing :/

  • @Mallard_Games
    @Mallard_Games 8 місяців тому

    very nice tutorial! thank you

  • @shezikhan5934
    @shezikhan5934 3 роки тому

    Bro Im building a cannom game wher cannon follows the mouse to aim I want to add a slider for android controls please help

  • @sarnax74
    @sarnax74 Рік тому

    THANK YOUUUUU amazing tutorial

  • @vampiretear
    @vampiretear 2 місяці тому

    you are the best!!! thank youuuuu

  • @mauroianni7532
    @mauroianni7532 2 роки тому

    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?

  • @nguyenquangha2917
    @nguyenquangha2917 2 роки тому

    Thanks! Help so much. Easy Explanation

  • @LikuidStudios
    @LikuidStudios 2 роки тому

    Awesome video thanks!

  • @Archrender360
    @Archrender360 3 роки тому

    You are best guy that I watched in youtube thanks thanks

  • @Zer0Morph
    @Zer0Morph 2 роки тому

    Brilliant!! Is there a way to isolate just the music volume, not the entire game?

  • @lukecm3225
    @lukecm3225 Рік тому

    Great lesson, thanks.

  • @entitydotexe6138
    @entitydotexe6138 3 роки тому +6

    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"

    • @ythedemon8742
      @ythedemon8742 3 роки тому

      Did you try
      private void Load()

    • @milpergunner
      @milpergunner 3 роки тому

      @@ythedemon8742 i have the same problem and i have the () at the end, no idea what causes the error message

    • @fanti8957
      @fanti8957 2 роки тому

      copy and paste here the script so i can help you

    • @Luckyhanni
      @Luckyhanni 2 роки тому

      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....

    • @md_rofique
      @md_rofique 2 роки тому

      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

  • @NguyenTran-hb5oe
    @NguyenTran-hb5oe 2 роки тому

    Nice and precise tutorial. Many thanks.

  • @Motyy
    @Motyy 2 роки тому

    How can i do this with arrow keys or + and -?

  • @samboekee5348
    @samboekee5348 3 роки тому

    nice tutorial worked first try and i understand the code

  • @bramwolters1393
    @bramwolters1393 Рік тому

    Thanks for the tutorial

  • @fredounet1247
    @fredounet1247 Рік тому

    Great Video !!

  • @josemarquez8581
    @josemarquez8581 3 роки тому

    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

  • @EIvinL
    @EIvinL 3 роки тому

    really good, helped me alot, keep it up bro

  • @486x
    @486x 3 роки тому

    how to do this with audio mixer?

  • @3x_UndrScr
    @3x_UndrScr Рік тому

    Thank you very much man.

  • @betguy-l2q
    @betguy-l2q Місяць тому

    Best sscripter thanks so much:3

  • @unitymakegame8003
    @unitymakegame8003 3 роки тому

    Awesome tutorial! Thank you!

  • @suaisojohnricg.2098
    @suaisojohnricg.2098 10 місяців тому

    very helpful really thank u

  • @noshippuden1923
    @noshippuden1923 2 роки тому

    Thank you a lot, very nice video and turorial keep it up

  • @knightgod
    @knightgod 3 роки тому

    thats awesome it helps me a lot thank you for all of your awesome usefull videos

  • @ankitshivam2764
    @ankitshivam2764 2 роки тому

    Really Great Tutorial

  • @Dalorini
    @Dalorini Рік тому

    Просто в шоке, очень простой скрипт и всё работает, как часы, лучшее видео.

  • @Galaxy_World
    @Galaxy_World 2 роки тому +2

    i must be dumb bc it doesnt work. i cant attach the script bc it tells me it cant have a script. wtf bruh

  • @darkmath100
    @darkmath100 2 роки тому

    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.

  • @joshuabrown604
    @joshuabrown604 3 роки тому

    Thank You So Much! You are a Legend! :D

  • @mskzchkn9168
    @mskzchkn9168 3 роки тому

    Man it's awesome!

  • @Sillymonkeies
    @Sillymonkeies 3 роки тому

    this works for all audio, right?

  • @fajarfauz5632
    @fajarfauz5632 5 місяців тому

    tysm hooson

  • @xdtygamer2617
    @xdtygamer2617 2 роки тому +1

    Thank you so much

  • @hassanmaswedish2290
    @hassanmaswedish2290 3 роки тому

    A heart by hooson is a dream!

  • @Mport-UK
    @Mport-UK 3 роки тому

    Thank You for this. Well Done! :D

  • @nithishprakash3042
    @nithishprakash3042 3 роки тому

    Thank you very much, bro you helped me a lot.

  • @indiandev1588
    @indiandev1588 2 роки тому +1

    I Like ur way teach

  • @aminullah5939
    @aminullah5939 2 роки тому

    plz make more video tutorials

  • @monstersocke7545
    @monstersocke7545 Рік тому

    Great!! Thanks a lot!

  • @davidbolivarg
    @davidbolivarg 3 роки тому

    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"

    • @servindothings
      @servindothings 2 роки тому +1

      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

  • @ajmaln2387
    @ajmaln2387 Рік тому

    ur the goat thanks

  • @jarirabbas3281
    @jarirabbas3281 3 роки тому

    Nice as always

  • @dvlzstare6419
    @dvlzstare6419 3 роки тому

    thanks you so much you are amazing

  • @kenj1dev686
    @kenj1dev686 Рік тому

    NICE. thanks

  • @marycarsanchez484
    @marycarsanchez484 3 роки тому

    why does mine doesnt save :(( pls help

  • @galactorsus_i.n.c
    @galactorsus_i.n.c 3 роки тому

    awesome tutorial

  • @Justarthie
    @Justarthie 6 місяців тому

    Even with this tutorial youtube couldn’t make a volume slider for their MUSIC app

  • @ciacca47
    @ciacca47 3 роки тому

    Thank you very much my friend

  • @xzioooo
    @xzioooo 3 роки тому

    Great video.

  • @aleksandraaleksandra7934
    @aleksandraaleksandra7934 11 місяців тому

    Thank you :-)

  • @arehman9529
    @arehman9529 3 роки тому

    Hey bro one video for unity touch inputs plz plz plz plz plz plz

  • @curiouskid1547
    @curiouskid1547 2 роки тому

    Thanks a lot.

  • @gamerbelike837
    @gamerbelike837 Рік тому

    Thanks❤

  • @joewebp
    @joewebp Рік тому

    Thanks a lot

  • @nguyentrunghieu6865
    @nguyentrunghieu6865 3 роки тому

    I like video and thank u very much

  • @saraaskeloph283
    @saraaskeloph283 2 роки тому

    Thank you!

  • @ademblack1129
    @ademblack1129 2 роки тому

    Thank you so much

  • @kraessa7950
    @kraessa7950 Рік тому

    very good