Vinhtrinh - Tin Tức Hay, Siêu Hot Cập Nhật Hàng Ngày
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính
No Result
View All Result
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính
No Result
View All Result
Vinhtrinh - Tin Tức Hay, Siêu Hot Cập Nhật Hàng Ngày
No Result
View All Result

Simple Sound Manager (Unity Tutorial)

admin by admin
June 15, 2020
in Tổng Hợp
38
Simple Sound Manager (Unity Tutorial)



Let’s learn how to play Sounds and create a simple Sound Manager class to handle playing any Sound we want in 2D and 3D.

GameAssets class video

If you have any questions post them in the comments and I’ll do my best to answer them.

See you next time!

Grab the game bundle at

Get the Code Monkey Utilities at

#unity3d #tutorial #unity2d

——————————————————————–

Hello and welcome, I am your Code Monkey and here you will learn everything about Game Development in Unity 2D using C#.

I’ve been developing games for several years with 7 published games on Steam and now I’m sharing my knowledge to help you on your own game development journey.

You can see my games at www.endlessloopstudios.com

——————————————————————–

– Website:
– Twitter:
– Facebook:

Nguồn: https://vinhtrinh.com.vn

Xem thêm bài viết khác: https://vinhtrinh.com.vn/tong-hop/

Xem thêm Bài Viết:

  • Cách làm 4 món thịt ngâm mắm tỏi chua ngọt thơm ngon ngày Tết
  • Sinh năm 1998 mệnh gì, tuổi con gì, hợp tuổi nào?
  • TUỔI TÂN HỢI SINH NĂM 1971 MỆNH GÌ, HỢP MÀU GÌ, HƯỚNG NÀO TỐT
  • Mách bạn cách làm hoa ly thủ công bằng giấy xinh xắn siêu đơn giản
  • Hướng dẫn trẻ mầm non cách vẽ xe đạp đơn giản nhất
Previous Post

Tạo file Ghost Win 10 bằng Norton Ghost dễ dàng (Không cần USB, đĩa CD)

Next Post

Chia sẻ cách khắc phục lỗi google chrome không vào được mạng

Next Post
Chia sẻ cách khắc phục lỗi google chrome không vào được mạng

Chia sẻ cách khắc phục lỗi google chrome không vào được mạng

Comments 38

  1. Code Monkey says:
    3 years ago

    Do you normally play your sounds through code or instantiate a prefab?

    Reply
  2. prolific8 says:
    3 years ago

    Really nice tutorial and exactly what I was looking for. One question – is there really no more efficient way in Unity/C# to find the AudioClip than looping through the array? I know it's only a small array but anything with O(n) complexity makes me uncomfortable!

    Reply
  3. John Shannon Perkins says:
    3 years ago

    Dude. Do you have any idea how good an instructor you are? I've been watching coding/unity videos for years. You are highly organized, extremely concise, and just a smart organizer of code. Level: Elite.

    Reply
  4. Gaban says:
    3 years ago

    Stopped the video at 1:52, 3 lines and the code is already gore, i can't believe a professional gamedev spread bad codings practices like that

    Reply
  5. RubberJoelzilla says:
    3 years ago

    How do you adjust audioclip volume with this method?

    Reply
  6. Aniket Ujgare says:
    3 years ago

    I have noticed for my ui button sometime the click sound is playing twice some time like normal just one time sometime not playing at all. What is the problem? may be the scene loads fast that the sound is not playing. Can you tell how to fix this

    Reply
  7. W Hc says:
    3 years ago

    Great Tutorial!

    Reply
  8. W Hc says:
    3 years ago

    Hello, I want to know how can we loop an Audio clip when the player is hitting a collider, if you have an idea of how can we do this using your script, I am very interested to hear your answer! Thank you for your reply!

    Reply
  9. Jason Bp Official says:
    3 years ago

    Very good tutorial! Thanks Code Monkey! 😉

    Reply
  10. Michael Marsh says:
    3 years ago

    How do you save the sound to PlayerPrefs to be accessed in a different script? I already have my audio manager written for my sliders, but cannot seem to transfer the playerprefs for my sound effects. Here is my code:

    using UnityEngine;

    using UnityEngine.UI;

    public class AudioManager : MonoBehaviour

    {

    private static readonly string FirstPlay = "FirstPlay";

    private static readonly string BackgroundPref = "BackgroundPref";

    private static readonly string SoundEffectsPref = "SoundEffectsPref";

    private int firstPlayInt;

    public Slider backgroundSlider, soundEffectsSlider;

    private float backgroundFloat, soundEffectsFloat;

    public AudioSource backgroundAudio;

    public AudioSource[] soundEffectsAudio;

    void Start()

    {

    firstPlayInt = PlayerPrefs.GetInt(FirstPlay);

    if (firstPlayInt == 0)

    {

    backgroundFloat = .25f;

    soundEffectsFloat = .75f;

    backgroundSlider.value = backgroundFloat;

    soundEffectsSlider.value = soundEffectsFloat;

    PlayerPrefs.SetFloat(BackgroundPref, backgroundFloat);

    PlayerPrefs.SetFloat(SoundEffectsPref, soundEffectsFloat);

    PlayerPrefs.SetInt(FirstPlay, -1);

    }

    else

    {

    backgroundFloat = PlayerPrefs.GetFloat(BackgroundPref);

    backgroundSlider.value = backgroundFloat;

    soundEffectsFloat = PlayerPrefs.GetFloat(SoundEffectsPref);

    soundEffectsSlider.value = soundEffectsFloat;

    }

    }

    public void SaveSoundSettings()

    {

    PlayerPrefs.SetFloat(BackgroundPref, backgroundSlider.value);

    PlayerPrefs.SetFloat(SoundEffectsPref, soundEffectsSlider.value);

    }

    void OnApplicationFocus(bool inFocus)

    {

    if (!inFocus)

    {

    SaveSoundSettings();

    }

    }

    public void UpdateSound()

    {

    backgroundAudio.volume = backgroundSlider.value;

    for(int i = 0; i < soundEffectsAudio.Length; i++)

    {

    soundEffectsAudio[i].volume = soundEffectsSlider.value;

    }

    }

    }

    Reply
  11. Jannick Breunis says:
    3 years ago

    I cannot initiate the GameAsset, "The object you want to initiate is null"…. Confusing.

    Reply
  12. Rafael Gonçalves says:
    3 years ago

    Lost me at 2:18 pulling out an entire script out of nowhere… man if it's essential to the tutorial why send us back to another tutorial 2 minutes in?

    Reply
  13. Nobody says:
    3 years ago

    i keep triggering the sound in the sound manager and it just creates an empty game object with an audio source with no audio clip, have i done something wrong?

    Reply
  14. Osvaldo García says:
    3 years ago

    Thanks for the video! I have a question, I want to play a sound for a button using the SoundManager and then change scene, but the scene changes very fast and doesn't wait for the sound finish. How can I add a WaitForSeconds on this SoundManager? I tried with corutines but can't add it to static class.

    Reply
  15. Jakub Nowak says:
    3 years ago

    Great tutorial, it is what I was looking for.

    Thank you for sharing your knowledge, you are awesome.

    I wil recommend you to my friends, and… if I will make someday game, I will add u in credits, u helped a lot, not just in this video.

    Stay safe!

    Reply
  16. Serg says:
    3 years ago

    How should I implement this with Unity mixer? So I can get audio settings?

    Reply
  17. Dimixtyz says:
    3 years ago

    Thank you so much <3

    Reply
  18. Certain Games says:
    3 years ago

    nice

    Reply
  19. Paul Brown says:
    3 years ago

    Anybody getting compilers errors on the foreach loop. Mine is saying it can't convert audio manager game asset

    Reply
  20. Azvitorツ says:
    3 years ago

    how do i make if enemy is chaseing me, sound start

    Reply
  21. Deesrex says:
    3 years ago

    Ok so the debug.logError. I get that error… Cant figure out what im doing wrong

    Reply
  22. Moreno Lovato says:
    3 years ago

    I'm sorry if I sound too rude, but this code is breaking too many good-programming rules that my heart is in pain.

    Reply
  23. Axel Estrada says:
    3 years ago

    Great video and explanation, helps me so much!!

    Reply
  24. DrunkBSshow says:
    3 years ago

    This is a great tutorial, but I'm getting an error. "ArgumentException: The Object you want to instantiate is null. UnityEngine.Object.CheckNullArgument(System.Object arg, System.String message)"

    Reply
  25. Enrique C. says:
    3 years ago

    you rulz!

    Reply
  26. Kavallo says:
    3 years ago

    I have modified your script to make easier volume and pitch setup with sliders: In the GameAsset script add 2 public float volume and pitch(with sliders),than modify this SoundManager methods like this:
    public static void PlaySound(Sound sound) {

    if (CanPlaySound(sound)) {

    if (!oneShotGameObject) {

    oneShotGameObject = new GameObject("Sound");

    oneShotAudioSource = oneShotGameObject.AddComponent<AudioSource>();

    }

    oneShotAudioSource.PlayOneShot(GetAudioClip(sound,oneShotAudioSource));

    }

    }

    private static AudioClip GetAudioClip(Sound sound,AudioSource audioSource) {

    foreach (GameAssets.SoundAudioClip soundAudioClip in GameAssets.i.soundAudioClips) {

    if (soundAudioClip.sound == sound) {

    audioSource.volume = soundAudioClip.volume;

    audioSource.pitch = soundAudioClip.pitch;

    return soundAudioClip.audioClip;

    }

    }

    Debug.LogError("Sound " + sound + " not found!");

    return null;

    }

    Now if u go in the GameAsset object you can adjust volume and pitch 🙂

    Reply
  27. Mohamed essam says:
    3 years ago

    i look for audio manager for me at all sites and youtube and i never found what i need,
    but you really are the best coder
    I have seen ,
    can you tell how i make a button to change sprite audio on and audio off like the image
    but with your code

    https://imgur.com/r5Sq91N

    and how to save Audio for every time i open the game by PlayerPrefs
    and thank you.

    Reply
  28. Алексей Лимонов says:
    3 years ago

    The best tutor! Thanks you!

    Reply
  29. Ahmed Samy says:
    3 years ago

    What if I attatched multiple audio sources components to game objects like component for the sword and play it from sword script when the attack happened I'm another audio source for the rute player when he moves ?

    Reply
  30. Ahmed Samy says:
    3 years ago

    Please can you show us how to make the same scene It looked very fancy

    Reply
  31. O o says:
    3 years ago

    Thanks a lot for your information rich tutorials. I hope you keep continuing.
    Instead of defining a dictionary and hardcoding delay timer in a switch-case for each clip, I defined two variables in the SoundAudioClip class, one for defining the delay value in the editor, one for storing last play time. then defined a CanPlay method in SoundAudioClip class.

    Reply
  32. KHALED Guesmi says:
    3 years ago

    I like your cool tutorials man please keep the best world

    Reply
  33. Kamski says:
    3 years ago

    Can you make a video about the infinite background(like the grass in this video)? I just want to know how to make something like this.

    Reply
  34. tesil123 says:
    3 years ago

    Make a discord server!!

    Reply
  35. Roy Meredith says:
    3 years ago

    Can i shoot a Ray cast out to an object instead of a straight line..the game I'm doing is a flight sim were the aim sight isn't always straight ahead cos of the camera offset..if you know what I mean

    Reply
  36. Syaeful Amri says:
    3 years ago

    Come here, cause your add

    Reply
  37. Nerd ishere says:
    3 years ago

    Nice tutorial but can you make a tutorial on tower defence game

    Reply
  38. Xanxus Varia says:
    3 years ago

    Wow finally the first time in my life youtube showed me a good add because i was searching for a game programmer and boom finally found someone thanks to a add wow 🙂

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Xem Thêm

Bạn nên khảo sát, tìm hiểu thật kỹ, so sánh để tìm được sự lựa chọn phù hợp

Hướng dẫn mua bán nhà Quận 7 dưới 3 tỷ đảm bảo chất lượng sống 

November 30, 2022
Bạn không nên mua bán đất nền Lai Châu chung sổ

5 lưu ý quan trọng khi mua đất nền Lai Châu mà bạn cần biết

October 27, 2022
Hình ảnh mua bán biệt thự quận Đống Đa 2

6 điểm cần lưu ý trước khi mua bán biệt thự quận Đống Đa

October 21, 2022
Hình ảnh chung cư Nam Từ Liêm 3

5 kinh nghiệm mua chung cư Nam Từ Liêm an toàn hữu ích

October 11, 2022
Hình ảnh bán nhà mặt phố quận Hai Bà Trưng 2

Kinh nghiệm bán nhà mặt phố quận Hai Bà Trưng

October 4, 2022
Hình ảnh mua bán nhà riêng quận đống đa 1

9 điều cần lưu ý khi mua bán nhà riêng quận Đống Đa lần đầu

September 27, 2022
  • Liên Hệ
  • Chính Sách Bảo Mật

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Bất Động Sản
  • Công Nghệ
  • Luật
  • Tài Chính

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.