Adding BGM And On/Off Sound Button - Easy Unity Tutorial

  Рет қаралды 44,264

Hooson

Hooson

Күн бұрын

In this unity tutorial, you'll learn how to add background music and make an on/off sound button for our game. Background music enables players to immerse themselves in the world at hand and brings players gaming experience to the next level. Adding a on/off sound button in your game settings gives players the option to play with or without sound.
➤Adventure On The Road: assetstore.unity.com/packages...
Timestamps:
0:00 Intro
0:18 Background Music Scripting
1:18 Sound Button UI Setup
1:50 Sound Manager Scripting
5:14 Conclusion
#Hooson #Unity3D
Play my first mobile game: Bot Attack - 2D Top-down shooter
➤Google Play: play.google.com/store/apps/de...
➤App Store: Coming soon
➤Follow my Instagram: / hoosontech

Пікірлер: 88
@hoosontech
@hoosontech 3 жыл бұрын
Hi guys! I have a tutorial on how to add a Volume Slider! Do check it out if you would like to add a Volume Slider instead of an On/Off Sound Button! kzbin.info/www/bejne/r4imeZSKrLuVos0
@losantosw
@losantosw 2 жыл бұрын
Thank you very much, I was already wondering where I would find another video where I would put in addition to the audio on and off options, a volume adjustment. Now I'll go to the next video to learn the other part lol
@VeronicaJessie
@VeronicaJessie 3 жыл бұрын
Thank you so much. You make this so simple and easy to understand!
@phellippemottarini
@phellippemottarini Жыл бұрын
WOW, easy, simple and PERFECT. Thank you!
@jasperhwong3341
@jasperhwong3341 2 жыл бұрын
Straight to the point, thanks a lot!
@KRaJWanders
@KRaJWanders 3 ай бұрын
the best one out there Had been looking for this for some days now. Thanks a lot bro, you saved me
@crispychips9868
@crispychips9868 Жыл бұрын
Thank you for making these videos they're a really big help
@kingstar9995
@kingstar9995 2 жыл бұрын
Hi i really like your channel man and your editing you also the explenation that you give us while you are working on it i really love it
@gabrielulate
@gabrielulate 3 жыл бұрын
Awesome video dude, keep it up!
@Blazikennnn
@Blazikennnn 3 жыл бұрын
thanks dude, it really helped me for my thesis project :D
@eddiea6569
@eddiea6569 3 жыл бұрын
Thanks for the tutorial, it helped!
@zamharir_
@zamharir_ 3 жыл бұрын
Thanks for this amazing tutorial, it really helped
@rodsal
@rodsal 3 жыл бұрын
Amazing Tutorial! You got a new sub :)
@saiganeshr1436
@saiganeshr1436 2 жыл бұрын
It really helped me alot today and in future, Thanks for this wonderful information
@CutyDina
@CutyDina Жыл бұрын
Very useful, thanks!
@megakumalasarihrp6785
@megakumalasarihrp6785 2 жыл бұрын
Thanks a lot, your tutorial work 👍
@yncor9756
@yncor9756 2 жыл бұрын
thanks dude! you're the best ;)
@alphaplus4969
@alphaplus4969 2 жыл бұрын
thank you very much. it helped me a lot
@hdggfhjb6768
@hdggfhjb6768 3 жыл бұрын
I like your tutorial. Because have good UI & TEXT on video for extra teach
@ahmedkhabar
@ahmedkhabar 2 жыл бұрын
Thanks A lot Man, New Subscribe ❤❤❤
@VIMES_
@VIMES_ 2 ай бұрын
thank you!
@chermainehoo214
@chermainehoo214 3 жыл бұрын
Great video!!
@makofujihara5533
@makofujihara5533 2 жыл бұрын
By the gods, you are a life saver T^T
@MegaTVscreen
@MegaTVscreen 2 жыл бұрын
@Hooson how would you add pressedState for the mute buttons with this solution you showed us in the video (changing sprites)? You know, to indicate to the users that the button was pressed (e.g. changing the sprite's color to indicate that). Right now utilizing your method I am unable to find a solution on how to do apply a pressed effect to the mute/unmute button. Any suggestions? Thanks 🙂
@dazniputra
@dazniputra 3 жыл бұрын
It worked. Thanks
@remybeaumont8089
@remybeaumont8089 2 жыл бұрын
Merci mec, tu m'as permis d'avoir 10%
@syedmuhammadalishah5684
@syedmuhammadalishah5684 2 жыл бұрын
Thanks Nice Work
@luck8762
@luck8762 Жыл бұрын
Thank you so much!!!!!
@indiestudio23
@indiestudio23 2 жыл бұрын
Thank You Brother...
@Asif-ze5hp
@Asif-ze5hp 7 ай бұрын
Great
@hasanboyhakimov9144
@hasanboyhakimov9144 2 жыл бұрын
Thank you bro
@ake.studio
@ake.studio 2 жыл бұрын
thanks for video
@sadksazdag851
@sadksazdag851 2 жыл бұрын
thank you bro
@oterobot
@oterobot Жыл бұрын
Thank you
@miguelespeso401
@miguelespeso401 Жыл бұрын
Congratulations It's an amazing video. I managed to do what I was looking for to see your video. I would be very grateful if you activated the subtitles in Spanish to fully understand your logic, I like how you explain your video, but I don't fully understand it.
@PixluxGames
@PixluxGames Жыл бұрын
Thanks
@losantosw
@losantosw 2 жыл бұрын
Hi @Hooson, I replicated this code to make something to turn sounds and effects on and off. The problem is that in the effects, where I set another audio, when I click the button it plays the audio sound again. I don't understand why this behavior, since they are two different scripts. Can you help me?
@enjoylearning8585
@enjoylearning8585 2 жыл бұрын
best one
@rizwanshaikh8175
@rizwanshaikh8175 2 жыл бұрын
save system is working properly the only issue is when I go to option menu it restart the setting (when I set muted and go to option menu its unmuted)
@CurtisJensenGames
@CurtisJensenGames 2 жыл бұрын
Tip for anyone wanting to mute all sound effects: write a script for the audio listener, not the audio source
@UpcomingChris
@UpcomingChris 2 жыл бұрын
The PlayerPrefs part of this isn't working like I'd expect, if I close the game, change scene or something, the music will always start on regardless if I turned it off or not and I don't know why, is there something I'm missing?, code is identical, isn't it mean to be persistently saved?
@neowb8495
@neowb8495 2 жыл бұрын
I have a problem, when I changed scenes the icon goes back to OnMusic, but last time i left it, it is on OffMusic icon
@saswatamohanta1023
@saswatamohanta1023 2 жыл бұрын
how would i do it to turn off only music and not sound effects? Pausing the audio listener turns off all the sounds
@shivaprasadkm5423
@shivaprasadkm5423 Жыл бұрын
Hello i got problem that is, whenever the game starts the sound off button is enabled its not saving as set in last game,i got same issue in slider also (as u pinned in comment video).any suggestions.
@weejunjie93
@weejunjie93 2 жыл бұрын
I know this a long time vid, but just to ask why at the unity On Click Part, I cant add Function to it
@talismanskulls2857
@talismanskulls2857 Жыл бұрын
I like the concept but i am using sliders to adjust audio source. how do i mute those/
@atokosto
@atokosto 2 жыл бұрын
🔥
@nguyentrunghieu6865
@nguyentrunghieu6865 2 жыл бұрын
I like video
@FranyxD
@FranyxD 3 жыл бұрын
i want to in one scene in specify dont play that music how can i do it?
@shahpranay1236
@shahpranay1236 2 жыл бұрын
what is the getkeydown replacement for android can u help please?
@xcade2652
@xcade2652 8 ай бұрын
Hi the buttons weren't showing up is there a reason to it why isnt it showing when i hit play?
@benjib20
@benjib20 3 ай бұрын
yo im having an issue where the on and off are on the screen at the same time. what do i do?
@vladimirvetchinnikov6916
@vladimirvetchinnikov6916 3 жыл бұрын
Please, help me. What should I write here? UpdateButtonIcon(); AudioListener.pause = muted; if I use AudioMixer public void MusicButtonOnOff() { if (mutedMusic == false) { mutedMusic = true; Mixer.audioMixer.SetFloat("Music", -80); } else { mutedMusic = false; Mixer.audioMixer.SetFloat("Music", 0); }
@abderrazeksimmou8753
@abderrazeksimmou8753 3 жыл бұрын
Script using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SoundManager : MonoBehaviour { [SerializeField] Image soundOnIcon; [SerializeField] Image soundOffIcon; private bool muted = false; // Start is called before the first frame update void Start() { if(!PlayerPrefs.HasKey("muted")) { PlayerPrefs.SetInt("muted", 0); Load(); } UpdateButtonIcon(); AudioListener.pause = muted; } public void OnButtonPress() { if (muted == false) { muted = true; AudioListener.pause = true; } else { muted = false; AudioListener.pause = false; } Save(); UpdateButtonIcon(); } private void UpdateButtonIcon() { if(muted == false) { soundOnIcon.enabled = true; soundOffIcon.enabled = false; } else { soundOnIcon.enabled = false; soundOffIcon.enabled = true; } } private void Load() { muted = PlayerPrefs.GetInt("muted") == 1; } private void Save() { PlayerPrefs.SetInt("muted", muted ? 1 : 0); } }
@HOJ2
@HOJ2 9 ай бұрын
thx bro!
@F.Fifie.
@F.Fifie. 2 жыл бұрын
why mine didnt have music if i change to different scene? please helppp
@rizwanshaikh8175
@rizwanshaikh8175 2 жыл бұрын
after going back to sound button it restart and play the music
@adsikaros9611
@adsikaros9611 3 ай бұрын
but it also muted the sfx how to make it only stop the bgm
@neomylusie2017
@neomylusie2017 3 жыл бұрын
why I have errors like, error CS0117: 'PlayerPrefs' does not contain a definition for 'Haskey' ??
@hoosontech
@hoosontech 3 жыл бұрын
Can I take a look at your script? You can post the codes here
@gomolemomelela6052
@gomolemomelela6052 2 жыл бұрын
k needs to be a capital letter, so it needs to be HasKey, not Haskey
@yncor9756
@yncor9756 2 жыл бұрын
HasKey
@texnofest
@texnofest 2 жыл бұрын
Please make this for vibrate
@sheejarajendran137
@sheejarajendran137 3 жыл бұрын
Ok bro it's working but there is a problem for me, when I mute my music and go to another scene and come back again but the audio is playing, it's not saving How to solve this
@sheejarajendran137
@sheejarajendran137 3 жыл бұрын
Please replay bro
@mcpedab7442
@mcpedab7442 3 жыл бұрын
Ya I was having the same issue. I had to do a bit of tweaking to the Sound Manager script but it now works. Here's the code using UnityEngine; using UnityEngine.UI; public class SoundManager : MonoBehaviour { [SerializeField] GameObject soundonImage; [SerializeField] GameObject soundoffImage; private bool muted = false; void Start() { muted = PlayerPrefs.GetInt("muted") == 1; if(muted == false) { soundonImage.SetActive(true); soundoffImage.SetActive(false); } else { soundonImage.SetActive(false); soundoffImage.SetActive(true); } if (PlayerPrefs.HasKey("muted")) { Load(); } else { PlayerPrefs.SetInt("muted",1); Save(); } AudioListener.pause = muted; } private void UpdateButtonIcon() { if(muted == false) { soundonImage.SetActive(true); soundoffImage.SetActive(false); } else { soundonImage.SetActive(false); soundoffImage.SetActive(true); } } public void OnButtonPress() { if (muted == false) { muted = true; AudioListener.pause = true; } else { muted = false; AudioListener.pause = false; } UpdateButtonIcon(); Save(); } private void Load() { muted = PlayerPrefs.GetInt("muted") == 1; } private void Save() { PlayerPrefs.SetInt("muted", muted ? 1 : 0); } } Just copy paste the script and reassign the values and it should work like a charm.
@sheejarajendran137
@sheejarajendran137 3 жыл бұрын
@@mcpedab7442 ok thank you bro 😃
@densaldanha
@densaldanha 2 жыл бұрын
@@mcpedab7442 Absolute life saver, thanks a lot!
@muraterguzel8795
@muraterguzel8795 Жыл бұрын
@@mcpedab7442 Thanks! This is working
@arindameika3805
@arindameika3805 3 жыл бұрын
that's very helpful thanks, btw, do you know how to add different BGM in different scenes?
@chsufyansharif2405
@chsufyansharif2405 3 жыл бұрын
yes i knowm
@arindameika3805
@arindameika3805 3 жыл бұрын
@@chsufyansharif2405 Do you have the tutorial?
@chsufyansharif2405
@chsufyansharif2405 3 жыл бұрын
@@arindameika3805 No i dont have tutorial
@himanshukharkar8886
@himanshukharkar8886 2 жыл бұрын
make your bgm script static and use dontdestroyonload() method, thats all
@AYANKHAN-eh6ve
@AYANKHAN-eh6ve 2 жыл бұрын
just add this to your very first scene, and the music will play all along until we exit the game.
@syedsadiq8631
@syedsadiq8631 3 жыл бұрын
Make a mobile game in unity plz
@IlyasMMVII
@IlyasMMVII 5 ай бұрын
Backgound Music: using UnityEngine; public class BackgroundMusic : MonoBehaviour { private static BackgroundMusic backgroundMusic; void Awake() { if (backgroundMusic == null) { backgroundMusic = this; DontDestroyOnLoad(gameObject); } else { Destroy(gameObject); } } } SoundManager: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SoundManager : MonoBehaviour { [SerializeField] Image soundOnIcon; [SerializeField] Image soundOffIcon; private bool muted = false; // Start is called before the first frame update void Start() { if (!PlayerPrefs.HasKey("muted")) { PlayerPrefs.SetInt("muted", 0); Load(); } else { Load(); } UpdateButtonIcon(); AudioListener.pause = muted; } public void OnButtonPress() { if (muted == false) { muted = true; AudioListener.pause = true; } else { muted = false; AudioListener.pause = false; } Save(); UpdateButtonIcon(); } private void Load() { muted = PlayerPrefs.GetInt("muted") == 1; } private void Save() { PlayerPrefs.SetInt("muted", muted ? 1 : 0); } private void UpdateButtonIcon() { if (muted) { soundOnIcon.enabled = false; soundOffIcon.enabled = true; } else { soundOnIcon.enabled = true; soundOffIcon.enabled = false; } } }
@SheReact
@SheReact 10 ай бұрын
Bro I don't understand
@daniionas2888
@daniionas2888 Жыл бұрын
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SoundManager : MonoBehaviour { [SerializeField] Image SoundONNIcon; [SerializeField] Image SoundOFFIcon; private bool muted = false; void Start() { if (!PlayerPrefs.HasKey("muted")) { PlayerPrefs.SetInt("muted", 0); Load(); } else { Load(); } UpdateButtonIcon(); AudioListener.pause = muted; } public void OnButtonPress() { if (muted == false) { muted = true; AudioListener.pause = true; } else { muted = false; AudioListener.pause = false; } Save(); UpdateButtonIcon(); } private void UpdateButtonIcon() { if(muted == false) { SoundONNIcon.enabled = true; SoundOFFIcon.enabled = true; } else { SoundONNIcon.enabled = false; SoundOFFIcon.enabled = true; } } private void Load() { muted = PlayerPrefs.GetInt("muted") == 1; } private void Save() { PlayerPrefs.SetInt("muted", muted ? 1 : 0); } }
@moshi1002
@moshi1002 10 ай бұрын
thanks mate
@sillyninja65
@sillyninja65 3 жыл бұрын
fuck me i hate coding.
@wimpykiddd
@wimpykiddd 3 жыл бұрын
I have trouble "Assets\script\SoundManager.cs(16,13): error CS0103: The name 'PlayerPref' does not exist in the current context" here the code void Start() { if (!PlayerPrefs.HasKey("muted")) { PlayerPref.SetInt("muted", 0); Load(); } else { Load(); } UpdateButtonIcon(); AudioListener.pause = muted; }
@hoosontech
@hoosontech 3 жыл бұрын
There is a slight typo error in line 16. It should be "PlayerPrefs.SetInt("muted", 0);". You're missing a letter "s" in your PlayerPref
@wimpykiddd
@wimpykiddd 3 жыл бұрын
@@hoosontech Hahaha XD my bad sorry, but thanks for the reply
@JuanFranco-mq7js
@JuanFranco-mq7js 2 жыл бұрын
Thanks
Simple Sound Manager (Unity Tutorial)
19:27
Code Monkey
Рет қаралды 121 М.
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 47 МЛН
She’s Giving Birth in Class…?
00:21
Alan Chikin Chow
Рет қаралды 6 МЛН
Flexible LOOT SYSTEM in Unity with Random Drop Rates
13:24
Creating a Mute Button in Unity
7:13
Unity Mechanics
Рет қаралды 8 М.
2D Movement in Unity (Tutorial)
21:09
Brackeys
Рет қаралды 3 МЛН
SCRIPTABLE OBJECTS in Unity
8:57
Brackeys
Рет қаралды 988 М.
Introduction to AUDIO in Unity
14:26
Brackeys
Рет қаралды 1 МЛН
unity for beginners - part 1
0:51
IndividualKex
Рет қаралды 383 М.
6 Minute PAUSE MENU Unity Tutorial
6:09
BMo
Рет қаралды 106 М.
Unity NavMesh Tutorial - Basics
11:38
Brackeys
Рет қаралды 1,1 МЛН
Smart Cool Products, #bike #shorts
0:20
Smart Channel
Рет қаралды 11 МЛН
Ball game on the board #shorts
0:29
Payman
Рет қаралды 4,5 МЛН
Результат невероятен🤯
0:39
Бутылочка
Рет қаралды 10 МЛН
New Gadgets! Bycycle 4.0 🚲 #shorts
0:14
BongBee Family
Рет қаралды 9 МЛН