Introduction to AUDIO in Unity

Поделиться
HTML-код
  • Опубликовано: 21 сен 2024

Комментарии • 1,7 тыс.

  • @mr.mysteriousyt6118
    @mr.mysteriousyt6118 7 лет назад +3322

    don't stop teaching us.

  • @TheGrimmGamer
    @TheGrimmGamer 3 года назад +430

    That feeling when you follow the tutorial, set everything up, tear your hair out for 3 hours wondering why the sound won't play... and then change the pitch from 0 to 1.

    • @stripeysoup
      @stripeysoup 3 года назад +19

      OMG THANK YOU.

    • @maxplayerone9565
      @maxplayerone9565 3 года назад +9

      The legend that saved me weeks of debuging- Grimm himself. Thanks dude!

    • @goodgamershow6505
      @goodgamershow6505 3 года назад

      @@maxplayerone9565 do we need to change [Range(0.1f, 3f)] of pitch variable to 1f,3f or what?

    • @goodusername4901
      @goodusername4901 3 года назад +2

      @@goodgamershow6505 i think you need to look at the Audio_Manager game object's script component

    • @persimmon93
      @persimmon93 3 года назад +1

      Your comment saved my hair. My hair thanks you.

  • @NightcoreMotion
    @NightcoreMotion 7 лет назад +571

    If anyone is curious on how to stop playing a looping sound (maybe you want to switch bg music when you enter a new area) just use s.source.Stop (); You can just add a method to the Audio Manager like this
    public void StopPlaying (string sound)
    {
    Sound s = Array.Find(sounds, item => item.name == sound);
    if (s == null)
    {
    Debug.LogWarning("Sound: " + name + " not found!");
    return;
    }
    s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
    s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
    s.source.Stop ();
    }
    just call it like this (AudioManagerReferenceGoeshere).StopPlaying("sound string name");

    • @arnedebeer
      @arnedebeer 7 лет назад +6

      Hey Nightcore Motion, I was just like you using s.source.Stop(), but it keeps giving me a NullReferenceException that the source equals to null, any idea on how to fix that?

    • @SasukeUchiha723
      @SasukeUchiha723 6 лет назад +17

      You should actually write it at the place where you want to stop bgm 1 and play bgm 2.
      if (blah blah){
      FindObjectOfType ().StopPlaying ("GameplayMusic");
      FindObjectOfType().Play("MenuMusic");
      }

    • @ItsBenniiBoii
      @ItsBenniiBoii 5 лет назад +4

      You sir, are a lifesaver!

    • @praveenkrishna8885
      @praveenkrishna8885 4 года назад +5

      I want to fade in the audio in start how to do that.

    • @kishiosakai2649
      @kishiosakai2649 4 года назад +1

      Wow thank you, I was trying for hours :D

  • @MT-nd5ut
    @MT-nd5ut 2 года назад +31

    For anyone that's struggling with ArgumentNullExceptions when you switch scenes, it's because you're referencing the wrong AudioManager. For example, if you switch scenes, the AudioManager in the scene gets destroyed by the singleton code, but you call Find() on it instead of the singleton instance of the AudioManager from a previous scene. In other words, you shouldn't use Find() but rather AudioManager.instance when referencing the AudioManager.
    In fact, if your game always starts at the main menu of your game then you only need one AudioManager instance in the main menu hierarchy, but I'd still recommend keeping AudioManagers in every scene.

  • @NewbNinjas
    @NewbNinjas 2 года назад +31

    OK Guys, for some of you that will likely be getting a Null:Exception Error you might need to check that you aren't trying to Play() the sound in an AWAKE function on another object. I had this problem and for about a month I've been pushing it to the side and figured I'd get around to fixing it later when it became a little more important.
    SO the problem I had was I used the same setup as in the tutorial, with another class I called Jukebox. This was to handle the current soundtrack playing and to allow players to cycle between other soundtracks in the game, like a Jukebox :D
    Long story short, I was calling the following lines of code:
    audioManager = FindObjectOfType();
    audioManager.Play("music_metal_1");
    within the Jukebox.Awake() function. This is a NO NO. The SOURCES aren't populated until later which means when I was trying to invoke them they hadn't actually been setup ;)
    To get around this I simply called the same code in the Jukebox.Start() function which worked absolutely fine.
    I hope this helps one other poor soul out there then I know my suffering was not in vain. This post isn't actively monitored so my query went almost 2 months without a single response. I hope this helps someone.
    Never Give Up

    • @Noobyoulus
      @Noobyoulus Год назад +1

      Thank you!!!

    • @TheBrunoRM
      @TheBrunoRM Год назад

      @@Noobyoulus So basically, only use Awake() to initialize the class that method is in, and use Start() to get references from other classes, making sure the other classes have already been initialized by the Awake method.

  • @In-N-Out333
    @In-N-Out333 6 лет назад +118

    Move these two lines of code:
    s.source.volume = s.volume;
    s.source.pitch = s.pitch;
    from Awake to the Play function. That way you can adjust those values in real time while the game is running.

    • @skiesquiggles7319
      @skiesquiggles7319 5 лет назад +2

      Brorger

    • @Diego0wnz
      @Diego0wnz 4 года назад

      How to control them all at once?

    • @DavidBixler
      @DavidBixler 4 года назад

      This doesn't work for me unfortunately.

    • @DavidBixler
      @DavidBixler 4 года назад

      So this works, except for the music. It doesn't seem to allow change at runtime for the currently playing sound.

    • @sumogre1822
      @sumogre1822 4 года назад

      @@DavidBixler How'd you do it?

  • @Joohyunsang
    @Joohyunsang 3 года назад +5

    This video is 4 years old, but it still legit!! I was struggling to find a way to manage game audio files until watching this. Many thanks to Brackeys!!

  • @aidan_byrne
    @aidan_byrne 4 года назад +17

    This is by far one of the most straightforward and easy to follow tutorials I have watched in quite a while!

  • @rigzmoviediaries654
    @rigzmoviediaries654 5 лет назад +44

    Brackeys, without you I would be lost and stuck paying for a course. Thank you.

    • @fv4202x
      @fv4202x 3 года назад

      how are you now?

    • @rigzmoviediaries654
      @rigzmoviediaries654 3 года назад +5

      @@fv4202x My interest in game development has definitely decreased, but my skills and craft have definitely increased. I'm still planning on releasing games one day.

    • @artyWeeb
      @artyWeeb 3 года назад

      @@rigzmoviediaries654 good luck

    • @cheesedabber
      @cheesedabber 2 года назад

      @@rigzmoviediaries654 and how is that going for you now?

  • @imconfused6955
    @imconfused6955 7 лет назад +799

    Is the audio just you making noises

    • @diegocrusius
      @diegocrusius 7 лет назад +11

      preprocessing with what, please?

    • @diegocrusius
      @diegocrusius 7 лет назад +5

      hmm I think I remember using audacity to cut and convert some audio files Didnt know you could go much further. Thanks.

    • @diegocrusius
      @diegocrusius 7 лет назад +5

      thank you for your kindess

    • @Brackeys
      @Brackeys  7 лет назад +632

      NO!
      ...
      Okay yeah :)

    • @chickentim8505
      @chickentim8505 6 лет назад +7

      xD

  • @LILMAN_official
    @LILMAN_official 4 года назад +3

    If you are new to coding and you arnt able to take classes I would suggest following along and paying attention with alot of beginner coding videos, it really does help, this channel its self is probably one of the best places to start.

  • @tonihenriksson2399
    @tonihenriksson2399 4 года назад +6

    I have watched your videos for ages , learning a shit ton from them.
    I just realized i never thanked you for the videos.
    So.. THANK YOU! You are really motivating me through my struggles :D

  • @Junglej0hn
    @Junglej0hn 6 лет назад +4

    Very nice solution, if I may add one thing then instead of finding the gameobject reference every time you want to play a sound, you could write a static function in the audiomanager:
    public static void PlaySoundStatic(string name)
    {
    if (instance == null)
    {
    Debug.Log("No audio manager ");
    return;
    }
    instance.PlaySound(name);
    }
    Then we use the current active audiomanager to play the sound. Then you would write "AudioManager.PlaySoundStatic(string mySoundName);" to play a sound from anywhere.

  • @localSunMan
    @localSunMan 6 лет назад +9

    Thank you a lot for this tutorial. I spent multiple days figuring out a way to keep the music nice and clean throughout scenes and after finding a somewhat working method, your tutorial is like a gift from the heavens (the internet heavens). Love your tutorials, love your good attitude, can't wait for the next one!

  • @diegocrusius
    @diegocrusius 7 лет назад +79

    if I could marry a youtube channel it would probably be this. One of the best Brackeys videos I saw so far.

  • @shehzaanansari8204
    @shehzaanansari8204 7 лет назад +144

    Great video as always!

  • @RealRushinRussian
    @RealRushinRussian Год назад +5

    I don't understand. So you design a custom Sound class that has most of the core data that a stock AudioSource already has. You then make a messy, obscure Inspector interface to interact with it - I mean, try to remove or add a sound from/to the middle of the list and see how that works... Only to just copy all the custom Sound data fields into the hidden AudioSources on Awake.
    What is the point of all of this other than to make everything obscure and ridiculously difficult to maintain once you have more than 2-3 sounds?
    Make an empty object that contains an AudioSource. Make a prefab out of it. Add a prefab instance for every sound you want to have; name your objects accordingly in the hierarchy. Make them all children of an AudioManager object. Take the whole object (with all children) and save them as a prefab as well. Just add this prefab to every scene. To add a new sound, simply go to prefab-editing mode and do what you must. No restrictions on deleting, adding, or changing the order of your sounds. No need to duplicate the data between a custom class and an actual AudioSource. You could even have separate sound lists per scene which is also super easy to set up.
    There are probably far better approaches to this as well, but this one is a straight up mess. Don't make lists of custom classes that you fully set up from the Inspector. Either load the data from a file (json, csv etc) or set it up with objects but don't go for the Inspector approach. Just the fact that you can't modify the order of your sounds alone should ring alarm bells. So should the data-duplicating. It's not viable for anything beyond a simple test scene. Like, I get that it's supposed to be a lesson for beginners but it's still a horrible approach.

    • @cjplanes
      @cjplanes Год назад +1

      Goddamn you are a genius

    • @tegxi
      @tegxi Год назад +1

      I like your method, it seems far less janky. Though given that this tutorial is 5 years old your hostility seems excessive.

  • @gamerheroine
    @gamerheroine 3 года назад +2

    I've rewatched this video so many times! Its such a good resource. Everytime I get to doing audio in a game I pull this up again for a refresher.

  • @codersexpo1580
    @codersexpo1580 4 года назад +4

    GREAT VIDEO! If I may add ...
    Since the audio "Name" is created when you add it to the Audio Manager, it might be best to add that name to the Audio Manager Enum. Like so...
    public enum AudioSounds
    {
    ShipEngineThruster = 0
    ,
    SomeOtherSoundName = 1,
    YetAnotherSountName = 2
    }
    ...and then from any component using the Sound Manager that sound can be called by name like...
    audioManager.Play(AudioManager.AudioSounds.ShipEngineThruster);
    ...and in the Audio Manager's method to Play, we have...
    public void Play(AudioSounds name)
    {
    var s = FindAudioClip(name);
    if (s != null)
    {
    if (!s.source.isPlaying)
    {
    s.source.Play();
    }
    }
    }
    private Sound FindAudioClip(AudioSounds name)
    {
    return Array.Find(sounds, sound => sound.name == Enum.GetName(typeof(AudioSounds), name));
    }
    I hope you like this addition ;-) Love the work you do!!

    • @codersexpo1580
      @codersexpo1580 4 года назад

      I also wanted to just add, if folks are not familiar with what you were doing @13:10, this is called a singleton pattern (which I believe he mentions) and I would highly suggest anyone not familiar with this pattern to research it. In fact Jason W @ ruclips.net/video/hQE8lQk9ikE/видео.html does a nice job of discussing this pattern as well as a few others often used in development. Thanks again for an awesome video.

  • @houssam3009
    @houssam3009 3 года назад +1

    The more I watch the more I miss you man thanks for all the awesome tutorials.

  • @nikitaprodanov5219
    @nikitaprodanov5219 5 лет назад +7

    It`s amazing that there are still people like you who keep helping others without wanting something for exchange. Love your vids. I wish you luck and don`t stop making this awesome tutorials.

  • @Aessa7
    @Aessa7 6 лет назад +1

    Dude I love your direct style, you don't waste ANY time, and you trust the viewer to understand. Thank you so much.

  • @marxiplier4322
    @marxiplier4322 3 года назад +5

    Finally, I've been looking at a bunch of overly complicated sound managers that I can't seem to get to work, and then you come along and make it so much simpler and actually work.

  • @hamez6970
    @hamez6970 2 года назад +2

    i love the way these guys made sounds, with their mouth

  • @johncisors4832
    @johncisors4832 7 лет назад +78

    Love your sound effects :D

    • @Brackeys
      @Brackeys  7 лет назад +23

      Haha, thanks! :)

    • @dmitrij34
      @dmitrij34 7 лет назад +2

      +Brackeys Why Array.Find? Why not a dictionary with try get value instead?

    • @sulthanfaez1135
      @sulthanfaez1135 5 лет назад

      Its just his voice

    • @place_holder2160
      @place_holder2160 3 года назад +2

      @@sulthanfaez1135 no shit sherlock

  • @tahahusain7328
    @tahahusain7328 4 года назад +1

    Please Don't Stop Teaching Us Unity, We All Love You And Your Tutorial's. Thanks For Teaching Us Unity For Free

  • @jasonallen2602
    @jasonallen2602 Год назад +9

    MAKE SURE you give the pitch a value that is NOT zero. Spent hours trying to figure out why my audio wasn't playing and realized it was because I never touched the pitch value and because it defaults to zero you get no sound.

  • @Random_Coffee_Cup
    @Random_Coffee_Cup 4 года назад +1

    I noticed that the car did not destroyed when you go forward in one way haha and u said make thing like when player go in one way for some time respawn one ticket on his way! Don't stop man your videos is helping a lot

  • @SpeedySpee
    @SpeedySpee 6 лет назад +10

    If you are still looking to download and the link doesn't work!
    Use this link.
    old.brackeys.com/wp-content/FilesForDownload/AudioManager.zip

  • @samuelleigh2270
    @samuelleigh2270 6 месяцев назад +1

    Still using this 6 years later! Thanks!

    • @IdleGamer208
      @IdleGamer208 6 месяцев назад

      me too

    • @michaelanonymous3104
      @michaelanonymous3104 29 дней назад

      me too but.... "MissingReferenceException: The object of type 'AudioSource' has been destroyed but you are still trying to access it" and no I didn't alter the code

  • @BestJohnEver
    @BestJohnEver 6 лет назад +5

    You rock man! Great programer, very organized and well explained! Thank you and never stop doing this videos!

  • @razorNeel
    @razorNeel 4 года назад

    I started creating a game without having any c# knowledge last week based on your cube game. Now it has 7 proper levels, both keyboard and touch controls and a save file system.

    • @razorNeel
      @razorNeel 4 года назад

      And now it has sound as well

  • @deaf_conformist
    @deaf_conformist 4 года назад +7

    Sorry, when I heard the first sound of the car, I had to stop the video, I couldn't stop laughing ... I was like "ok, it is going to show us a professional car sound, recorded with a good mic ...." and suddenly ... "fffrrruuuuuummmmMMM"

  • @rastarish3201
    @rastarish3201 7 лет назад +2

    Quite possibly, one of the most useful Unity tutorials I have ever come across! Thanks Brackeys!

  • @lunarfoxgames
    @lunarfoxgames 2 года назад +3

    Anybody watching this now who doesn't want to mess around with the pitch each time, just change this in Sound.cs:
    public float pitch = 1f;
    This will default the pitch in the inspector to 1, that way you don't need to manually do it each time. You can also make the volume at a default like this.

    • @Ajaxlancer
      @Ajaxlancer 2 года назад

      Would you know how this would manage a PlayOneShot function? For instance, I have a gun that fires automatically and I don't want the sound to cut itself off without playing the full firearm sound effect.

  • @umadkuzubad
    @umadkuzubad 3 года назад

    You are amazing! Years later and I'm still using your videos with great success. Thanks Brackeys.

  • @turkym7md5
    @turkym7md5 6 лет назад +24

    1:36 i could say that you stick your mouth on the microphone and say "phooooophooooooophoooooo" xD

  • @ignatiusreilly8280
    @ignatiusreilly8280 4 года назад

    The visuals and lighting and smoke are awesome looking in that little game.

  • @Retr-eo5uz
    @Retr-eo5uz 7 лет назад +238

    You're the best !

  • @oxenfree6192
    @oxenfree6192 5 лет назад +1

    You're an amazing instructor. Please never stop. Your videos are so clean and direct, and you cover information so well.

  • @shreddernation1096
    @shreddernation1096 5 лет назад +9

    My dude made a game about king Kai’s planet 😂😂 great vid man!

  • @SuperDutchrutter
    @SuperDutchrutter 3 года назад +1

    So useful. Going to miss the new uploads but hope your new adventures suit you well.

  • @Kaikaku
    @Kaikaku 7 лет назад +14

    Good timing, so far I have no audio in my program. This will now change :)

  • @VirtualTurtleGames
    @VirtualTurtleGames 7 лет назад +2

    It's amazing how by watching these videos I learn about how little I know of coding. I love that feeling because it means there is so much more to learn! Thanks for the videos ":D

  • @IronDizaster
    @IronDizaster 5 лет назад +278

    *you know, coding is easier than you think.*

    • @synthjc5105
      @synthjc5105 5 лет назад +35

      You Know You ShOuLd TaKe ThIs OnlNe UniTy On UnEdEmy

    • @shk_
      @shk_ 5 лет назад +9

      @liberP lovPrimeNumbers YoU KnOw YoU dO

    • @Ab-gj1jw
      @Ab-gj1jw 4 года назад +19

      You know, coding is easier than you think when you just copy.

    • @apainush9540
      @apainush9540 4 года назад

      change my mind

    • @TGR-ll8mc
      @TGR-ll8mc 4 года назад

      @@synthjc5105 fucking hate that ad

  • @jroenning
    @jroenning 4 года назад +2

    all your videos are just so easy to use and straight to the point
    thank you so much

  • @AboA7ma11
    @AboA7ma11 4 года назад +3

    Use this function to adjust volume in runtime
    public void adjustvolume(float volume, string name)
    {
    sounds s = Array.Find(sounds, sound => sound.name == name);
    s.source.volume = volume;

    }

    • @AboA7ma11
      @AboA7ma11 4 года назад

      @@flaymes make sure the other class name is "sounds"

    • @AboA7ma11
      @AboA7ma11 4 года назад

      @@flaymes do adjustvolume("musicname", Slider.value);

    • @ptaroworm7887
      @ptaroworm7887 2 года назад +1

      Dude, you're a life saver. This is exactly what I was looking for. Thank you

    • @Somewhere_sometime_somehow
      @Somewhere_sometime_somehow 2 года назад

      @@AboA7ma11 I wanna use this but I'm stupid. What other class do you mean. You add this to the audiomanager right? I do have an array called sounds[ ] in my AudioManager script?

    • @AboA7ma11
      @AboA7ma11 2 года назад +1

      @@Somewhere_sometime_somehow yeah just paste this into your audio manger as a method and use it as any other method in your script. just make sure when you call it you input a value or a variable as your volume :D

  • @GerGauss
    @GerGauss 3 года назад

    This video has just saved me. I have been struggling for a week with this issue, I should have known better and have come here earlier

  • @AlineoRykkeErrel
    @AlineoRykkeErrel 6 лет назад +11

    In case you want to make a transition between two musics when you start another one, I made two coroutine to do that ;) the old music fade and the new one start progressively at the same time
    private Sound sound;
    public void Play(string name) {
    StopAllCoroutines();
    if (sound != null) StartCoroutine(EndSound());
    sound = Array.Find(sounds, s => s.name == name);
    if (sound == null) {
    Debug.LogWarning("Music " + name + " not found.");
    return;
    }
    StartCoroutine(StartSound());
    }
    private IEnumerator EndSound() {
    AudioSource oldSound = sound.source;
    while (oldSound.volume > 0) {
    oldSound.volume -= 0.01f;
    yield return null;
    }
    oldSound.Stop();
    }
    private IEnumerator StartSound() {
    sound.source.Play();
    float volume = 0f;
    do {
    sound.source.volume = volume;
    volume += 0.01f;
    yield return null;
    } while (sound.source.volume

    • @Viralfanatics
      @Viralfanatics 3 года назад

      Idk if you'd see this or reply but what is old sound here. I am a beginner so I can't really understand that.

    • @AlineoRykkeErrel
      @AlineoRykkeErrel 3 года назад +2

      @@Viralfanatics Hey, oldSound is a copy of the music currently playing. This way, I can have the "old" music playing with the new one at the same time. And I can fade out the old sound to a volume of 0 and stop it to make a smooth transition between the 2 musics

    • @Viralfanatics
      @Viralfanatics 3 года назад

      @@AlineoRykkeErrel Oh Thanks. I want my music to fade out as I change scenes and in the next one I want another track to fade in. I have been trying to figure it out for hours now and I haven't been successfull yet :')
      Can you help me with that?

    • @Viralfanatics
      @Viralfanatics 3 года назад +1

      Nevermind. I figured it out. Thanks a ton. Your comment helped a lot!!

    • @AlineoRykkeErrel
      @AlineoRykkeErrel 3 года назад

      @@Viralfanatics you're welcome haha, did you use DontDestroyOnLoad?

  • @nextcent
    @nextcent 4 года назад +2

    Fantastic tutorial! So useful! I had a problem in the Singleton code, because we had a "return" there, the sounds array was not being processed when the game went from level 1 to level 2 and I was getting a null reference error. I removed the "return" and everything worked fine. Thank you for sharing this.

  • @TigaLionessArt
    @TigaLionessArt 4 года назад +13

    Okay, so I know this video is like a thousand years old and probably nobody will help me, but I did this tutorial (with success) on one of my projects in Unity 2018.4.10f and it worked. Now I'm doing the exact same thing in 2019.3.0f5 and it's not working at all. After hitting play the Audio Source is created for a sound I add in AudioManager, it has the proper amount of volume and it's not playing. When I manually add an Audio Source on some other object (like Brackeys did in the beginning of the video) it works and the sound is played properly. Can it be the fault of the Unity version, or am I just doing something wrong?

    • @sulkingcrow7426
      @sulkingcrow7426 4 года назад +4

      I'm not sure if this is still relevant but I had the same problem and had to set the pitch to 1

    • @TigaLionessArt
      @TigaLionessArt 4 года назад +3

      @@sulkingcrow7426 Yeah I figured it out a day later. The script had mininal value of pitch set to 0.1, but it was written .1 so I had missed the fact it's not 1. And Unity treats any value of pitch under 1 as if it was set to 0. But anyway, maybe someone will have a similar problem and get to learn quicker what was wrong, than I did ;)

    • @SillyCraftersOcCheng2000
      @SillyCraftersOcCheng2000 4 года назад +2

      @@TigaLionessArt Thank god i see the comments here so can finish my game devoloping project for uni

    • @jhgfghjfuzrtfchchghgf
      @jhgfghjfuzrtfchchghgf 3 года назад +1

      @@sulkingcrow7426 thanks for posting this! I was trying to get this to work for over an hour. this tutorial is broken :(

    • @sulkingcrow7426
      @sulkingcrow7426 3 года назад

      @@jhgfghjfuzrtfchchghgf no problem! And it was a great tutorial, just a small (but important) part got looked over

  • @micnasr
    @micnasr Год назад +2

    4 years later and I am still using the same Audio Manager that I used in 2019 lol

  • @santoshpss
    @santoshpss 5 лет назад +4

    I would love the “48 Hour Game Challenge” to be shown as a tutorial step by step. At a maximum time of 4 hours... 😀😃😄😁

  • @pedrosalaspinero7220
    @pedrosalaspinero7220 4 года назад +1

    YOU RESCUED ME FOR MY FIRST GAME JAM LOVE YOU FOREVER

  • @zacharyseebeck2409
    @zacharyseebeck2409 7 лет назад +10

    I can't get any sound to come through. Even when directly copying and using your script. I can run the code with no error, but no sound either.

    • @ferguslees7994
      @ferguslees7994 7 лет назад

      Got the same issue here, appears in the audio manager but does not play...

    • @jeroeno_boy149
      @jeroeno_boy149 6 лет назад

      same

    • @Shavinderyt
      @Shavinderyt 6 лет назад +10

      late reply, but for other people, make sure your pitch is above 0. 1 is the normal sound without any pitch changes. and volume needs to be up too! this worked for me

    • @DarthZmex
      @DarthZmex 6 лет назад

      Was working until I set it as a prefab, then even trying again from the begining it didn't work, the pitch is well set also

    • @jeroeno_boy149
      @jeroeno_boy149 6 лет назад

      try design your own, worked for me

  • @sumitgohil2636
    @sumitgohil2636 7 лет назад

    You're one of the best online tutor I've came across. There's a lot to learn from you. Please don't stop teaching and keep doing this wonderful deed. God Bless You.

  • @ARTHUR14523
    @ARTHUR14523 4 года назад +5

    Now how do we play these sounds from the Master mix that we made in your other video so we can decrease volume from the slider?

  • @waterandtreefilms
    @waterandtreefilms 6 лет назад

    MY GOD!!!! Your tutorials have come a long long way! i think you have cracked the key to making the best tutorials. Fast but explanatory. New Fav GameDev Channel

  • @diablo4ever868
    @diablo4ever868 2 года назад +3

    does anyone have a link to the audio manager download? looks like the link in the video is broken

    • @DaMaLZ
      @DaMaLZ 2 года назад +1

      same

    • @afrorecording
      @afrorecording 2 года назад

      @@DaMaLZ actually it works hahah

  • @mohammedzaidkhan5687
    @mohammedzaidkhan5687 3 года назад +2

    The only tutorial I didn't understand by brackeys

  • @nonnodacciaio704
    @nonnodacciaio704 7 лет назад +16

    What if I want to stop the theme music, for example when Player dies?

    • @Yar3920
      @Yar3920 6 лет назад +1

      Nonno d' acciaio then destroy the audio manager

    • @JasonEkonomakos
      @JasonEkonomakos 6 лет назад +9

      No, don't destroy the audio manager, why would he do that? Simply call the music using the audio manager and either pause it or stop it

    • @dadmanful
      @dadmanful 6 лет назад +1

      lol

    • @zoewalker2064
      @zoewalker2064 5 лет назад +2

      @@JasonEkonomakos how tho???

    • @JasonEkonomakos
      @JasonEkonomakos 5 лет назад +5

      @@zoewalker2064 I have a different set up for my audio manager, but, looking back at this video, notice how he sets up the Play function. In the audio manager, Play takes a string input and finds the audio file with that name. The quickest solution to your problem is simply copy and paste the Play function, rename it Pause, and instead of writing "s.source.Play()" write "s.source.Pause()". Then when you want to pause a sound, just call the audio managers pause function and pass the audio files name as the input

  • @veno501
    @veno501 7 лет назад +2

    Well done tutorial, well done! Even has some more of that delicious advanced stuff, and helps a lot in understanding HOW TO MAKE CLEAN CODE which is indeed important

  • @taragitaratayo2304
    @taragitaratayo2304 6 лет назад +11

    Hey man! quick question, I've succesfully added the Audio manager , problem occurs when i try to combine the adding settings and slider control / mixer in my game . since yours creates a a new component .. how would i go about adding the mixer source on the component via script. Many thanks!

    • @Averysh
      @Averysh 5 лет назад +3

      Did anyone figure this out yet?

    • @kingdavegamess
      @kingdavegamess 5 лет назад +17

      @@Averysh if you did the "Introduction to AUDIO in Unity" you need to add another component to the Audio Manager and Sound Class .
      in the Audio Manager :
      s.source.outputAudioMixerGroup = s.group;
      in the Sound :
      public AudioMixerGroup group;
      and then add in the group : "Master(MainMixer)" I did so
      and it worked ,hope it helps .

    • @serbaneduard5045
      @serbaneduard5045 4 года назад +1

      @@kingdavegamess thx. You help me a lot.

    • @kingdavegamess
      @kingdavegamess 4 года назад

      @@serbaneduard5045
      no problem

    • @isaialusuardi
      @isaialusuardi 4 года назад +1

      @@kingdavegamess Thx it works!!!!

  • @sampleMEGdoor
    @sampleMEGdoor 5 месяцев назад

    I was left scratching my head after the video, I MEAN, WHAT THE FRICK?! THIS IS SO COMPLEX

    • @user-account-not-found
      @user-account-not-found 3 месяца назад

      Not really - pretty basic honestly. If you are new to programming I could see why this might seem difficult.

  • @BlaZeLiink
    @BlaZeLiink 7 лет назад +9

    Could you make a video about handling animation?
    For example: Weaponswitching in a fps
    You got an animation for putting down the current weapon. You also got an animation to pull out the second weapon.
    I implemented it one way, but it's not clean. I implemented a class, which starts a couroutine, which sets a bool in the animator of my current weapon, waits a second so it's finished, and then plays the next animation.
    I saw a lot of "tutorials" which try to create an animator-script. I don't think this apporach is good either.

    • @tudordumitrescu8707
      @tudordumitrescu8707 7 лет назад +1

      DerLink he literally did a vid a week ago on this

    • @BlaZeLiink
      @BlaZeLiink 7 лет назад

      if you refer to his weapon switching tutorial, that's not what I meant (not quite)
      I meant a tutorial about how to handle animation, I. e. import from a blend file, using mecanim.
      Like, wait for animations to finish using couroutines, implement clean animation transitions, the best way to implement animator controllers with blend trees, etc...

    • @jrgen7527
      @jrgen7527 6 лет назад

      I think maybe you should look into state machines @DerLink

  • @Toopa88
    @Toopa88 4 года назад

    The Sound class can be changed to a ScriptableObject in literally one minute. All you have to do is derive from ScriptableObject and add this:
    _[CreateAssetMenu(fileName = "sound_name", menuName = "ScriptableObjects/Sound")]_
    above the class name. Then you can create new Sound objects, define the values and drag all of them into the AudioManager in one go. Furthermore, your sound-settings will be saved at an actual place, which is a huge benefit.
    PS: as this will delete your previously defined values, you should make a screenshot of them to not lose time.

  • @gdzantaf6144
    @gdzantaf6144 5 лет назад +6

    is there a way to cancel sounds(like music) by having some kind of stop method?

    • @gdzantaf6144
      @gdzantaf6144 5 лет назад +1

      @@kadir9629 Thx

    • @vrstepper1204
      @vrstepper1204 3 года назад

      @@gdzantaf6144 StopMusic.cs(10,19): error CS0103: The name 'Array' does not exist in the current context.

    • @khnuxsora
      @khnuxsora Год назад

      @@gdzantaf6144 can you tell me how you did it?

  • @EduardoYukio
    @EduardoYukio 5 лет назад +2

    Absolutely awesome tutorial, you go right to the point, speak clearly and very efficiently! Thank you very much!

  • @AlexVoxel
    @AlexVoxel 7 лет назад +3

    Nice sound effects

  • @skyacaniadev2229
    @skyacaniadev2229 5 лет назад +1

    Those lovely mouth-crafted audio clips...

  • @omgtntlol
    @omgtntlol 5 лет назад +10

    0:37 for some reason I heard "Lets add some silence" XDXDXD

    • @marcuionut6319
      @marcuionut6319 3 года назад

      if I think about "Lets add some silence", I hear "Lets add some silence"
      but if I think about "Lets add some sounds", I hear "Lets add some sounds"
      Black magic

  • @Vero2726-s8u
    @Vero2726-s8u 2 года назад

    This is such a nice video, I'm starting with Unity now so I dint get much of the code part but I can see how great the Audio Manager is. Thank you so much !

  • @Dezmondo777
    @Dezmondo777 6 лет назад +27

    The link to Audio Manager is not available anymore :((

    • @jeroeno_boy149
      @jeroeno_boy149 6 лет назад +34

      old.brackeys.com/wp-content/FilesForDownload/AudioManager.zip

    • @seifmustafa2004
      @seifmustafa2004 6 лет назад +4

      thanks mate :)

    • @MINTYBIBI
      @MINTYBIBI 5 лет назад +3

      @@jeroeno_boy149 thx u so much

    • @DexterCrappell
      @DexterCrappell 6 месяцев назад

      ik, and it hurts cuz i need it to find my issues. I CANT FIND ANOTHER VIDEO THAT SHOWS MY FKN PROBLEM!@!!!@@!@@!@!@!!!!@@!

  • @MQNGameDev
    @MQNGameDev 4 года назад +1

    Love your videos. Thanks. I wanted to mention that you don't care about logging an error if the Array.Find() method returns null, you can always take advantage of the 'null-conditional operator' (or Elvis-Operator)::
    public void Play(string name)
    {
    Sound s = Array.Find(m_sounds, sound => sound.Name == name);
    //if (s != null)
    s?.Source.Play();
    // ? operator basically acts like a short-circuit if s is null, by ignoring the rest of the line of code.
    // If we have more code here that we don't want to execute if s is null, then using the initial approach is probably a better solution.
    }
    It might take a bit to get used to the syntax but they cut down on typing and those annoying if( something == null) blocks. I use this operator all the time with Delegate/events: OnSomeEvent?.Invoke();
    Cheers

  • @maxageev3dart
    @maxageev3dart 4 года назад +4

    How to adjust volume witch a slider in this AudioManager? Tried to add a new method for this but its dose not appears in functions while referencing AudioManager in a slider.
    public void AdjustVolume(float volume, string sound)
    {
    Sound s = Array.Find(sounds, item => item.name == sound);
    s.source.volume = volume;
    }
    How to make it work, please help ?

    • @sean6269
      @sean6269 3 года назад

      Did you ever figure it out?

    • @maxageev3dart
      @maxageev3dart 3 года назад

      Sorry man. Don't remember. That's was almost a year ago.(( I already probably lost the project where was using this thing.

    • @sean6269
      @sean6269 3 года назад

      @@maxageev3dart I got it ;) he made another video on an options menu that was pretty similar to what I was trying to do

  • @user-account-not-found
    @user-account-not-found 3 месяца назад

    A few improvements here would be to move the audio name to use an enum, the other part would be to trigger these based on state events rather than referencing and calling the audio manager itself.

  • @jeevat8164
    @jeevat8164 6 лет назад +8

    0:36 "Let's add some silence"

  • @stevanivanovic9579
    @stevanivanovic9579 Год назад +1

    Love the car voiceover work

  • @affe7130
    @affe7130 5 лет назад +5

    How would I go about adding volume sliders to some of the sounds in my AudioManager?

    • @train_guy
      @train_guy 4 года назад

      Check out Brackeys How to Make a Settings Menu in Unity Video and he explains how you can make an options menu and change the value of the volume
      ruclips.net/video/YOaYQrN1oYQ/видео.html

  • @milomakesstuff2019
    @milomakesstuff2019 4 года назад

    Thank you! It's working in my VR demo! You can here a hit sound now when you hit an enemy with your sword

  • @CeretPenyok
    @CeretPenyok 7 лет назад +22

    I can't hear the sounds when the object instantiated.

    • @benbuehler4972
      @benbuehler4972 5 лет назад +14

      pitch needs to be at least .1f for sound to be made.

    • @maiskorrel
      @maiskorrel 4 года назад

      @@benbuehler4972 Thanks!

    • @TheNamelessTO
      @TheNamelessTO 4 года назад

      @@benbuehler4972 Thank you!!

    • @cerisskies
      @cerisskies 4 года назад +1

      @@benbuehler4972 Life saver, I've been going mad here

    • @spacedog2980
      @spacedog2980 3 года назад

      @@benbuehler4972 thank you legend

  • @pranavakp9960
    @pranavakp9960 4 года назад

    You are the best teacher for coding games!!!

  • @animemotivasiofficial
    @animemotivasiofficial 2 года назад +3

    if your voice doesn't sound(Maybe because of different version), add code, s.source.Play()
    foreach(sounds in sounds)
    {
    s.source = gameObject.AddComponent();
    s.source.clip = s.clip;
    s.source.Play(); (Add This Code)
    s.source.volume = s.volume;
    s.source.pitch = s.pitch;
    }
    Hope you can help

  • @KaiBeatbox0803
    @KaiBeatbox0803 4 года назад

    damn I really like the way the Brackeys always give us the whole script and also teach us how to script yourself at the same time.

  • @Ninja1k1
    @Ninja1k1 7 лет назад +35

    great :)

  • @ravestechworld6445
    @ravestechworld6445 4 года назад +1

    Thank you soooo much bracks you have no idea how many people have you helped!

  • @gaweringo
    @gaweringo 7 лет назад +7

    am am trying to implement sounds into my games since 2 months, but unity is somehow not playing any of my audio files. Does anyone have an idea on how ti fix this problem?

    • @SasukeUchiha723
      @SasukeUchiha723 7 лет назад +1

      im having the same issue

    • @Axedogames
      @Axedogames 7 лет назад

      Have you the volume option at maximum ? Is unity no muted in your Volume mixer ?

    • @Axedogames
      @Axedogames 7 лет назад +1

      Is your AudioSource near an AudioListenner ?

    • @d1nkum340
      @d1nkum340 4 года назад +1

      check the mute audio button isnt checked, its next to gizmos

  • @8bytegaming139
    @8bytegaming139 6 лет назад

    If I need to know something I usually go to Brackeys first, love all of these videos.

  • @Ben-qn3py
    @Ben-qn3py 5 лет назад +4

    I can Play music but I can't stop it. How do i do that?

    • @GeorgeWulfers_88
      @GeorgeWulfers_88 4 года назад

      You would need to call Stop() on the audio clip.

    • @vrstepper1204
      @vrstepper1204 3 года назад

      @@GeorgeWulfers_88 how please? AudioManager.instance.Stop("MyMusic"); does not work.

  • @fateshow5303
    @fateshow5303 3 года назад

    This is the only video that I've found that has successfully worked for me. Thank you!

  • @Red_Dead_Chris
    @Red_Dead_Chris 6 лет назад +4

    The link for the download do not work anymore :(

  • @dartutorials7859
    @dartutorials7859 4 года назад +2

    if you cant hear sound in unity you might have to go into project settings - audio and uncheck "mute audio" or set master volume to 1 or in your game view at the top bar uncheck mute audio

  • @appswithjeffgarcia7363
    @appswithjeffgarcia7363 5 лет назад +3

    Error. The name 'Array' does not exist in the current context
    anyone else get this message??

    • @appswithjeffgarcia7363
      @appswithjeffgarcia7363 5 лет назад +9

      Guys i actually solved this by putting, using System;

    • @prakharmathur1718
      @prakharmathur1718 5 лет назад +1

      @@appswithjeffgarcia7363
      Thank you
      Got struck on this for a long time

    • @superzooper
      @superzooper 5 лет назад +1

      @@appswithjeffgarcia7363 Thanks, really helped me!

  • @gulraiz19
    @gulraiz19 2 года назад +2

    Move these two lines of code:
    s.source.volume = s.volume;
    s.source.pitch = s.pitch;
    in Update() function in the AudioManager Script.
    Like this:
    private void Update()
    {
    foreach (Sound s in sounds)
    {
    s.source.volume = s.volume;
    s.source.pitch = s.pitch;
    }
    }
    That way you can adjust those values in real time while the game is running.

    • @shadbh2
      @shadbh2 2 года назад +1

      genius

  • @fajriard3504
    @fajriard3504 5 лет назад +31

    Better in 0.75 speed haha.

    • @moinsharif243
      @moinsharif243 4 года назад +1

      we have pause options ... haha

    • @mdlol69
      @mdlol69 4 года назад +1

      @@moinsharif243 You guys have options?

    • @beri4138
      @beri4138 3 года назад

      Haha computer go brrrrr

  • @ishaanchauhan3169
    @ishaanchauhan3169 7 лет назад

    i love how you are going over each topic. thank u sm

  • @davidenale17
    @davidenale17 7 лет назад +5

    great video as always!
    and...
    1) how to make that grass shader?
    2)do you know how to "sync" first person arms with the character body graphics?(a mask is enough?)

    • @mokafi7
      @mokafi7 7 лет назад

      good ideas! i hope he does them!

  • @edwardvo1875
    @edwardvo1875 4 года назад +1

    guys! if you want to play rapid sounds in succession without the sounds interrupting each other add this to your audiomanager script!
    public void PlayOneShot(string name)
    {
    Sound s = Array.Find(sounds, sound => sound.name == name);
    if (s == null)
    {
    Debug.LogWarning("Sound: " + name + " not found!");
    return;
    }
    s.source.PlayOneShot(s.source.clip, s.source.volume);
    }
    and then call it like this :
    AudioManager.instance.PlayOneShot("AUDIO_NAME");

  • @LRMTB
    @LRMTB 4 года назад +3

    i know this vid is quite old so probs no one will help, but how do you make it so that the music continues through the levels???? whenever i start a new level it starts the music from the beginning.

    • @shacharrodrigez7521
      @shacharrodrigez7521 3 года назад +1

      just make the music go again when the scene open

    • @LRMTB
      @LRMTB 3 года назад +1

      @@shacharrodrigez7521 yh the thing is i want it to continue from where it left off in the last scene

    • @cearaj405
      @cearaj405 3 года назад +1

      idk if you already found it out but just watch everything after 12:11

    • @LRMTB
      @LRMTB 3 года назад +1

      @@cearaj405 ah ok thanks lol

  • @revalreval
    @revalreval 6 месяцев назад

    This has its pros and cons, i feel assigning an audioclip and passing it into the Play() function is better