Simple Sound Manager (Unity Tutorial)

Simple Sound Manager (Unity Tutorial)

Code Monkey

5 лет назад

122,143 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Code Monkey
Code Monkey - 10.03.2019 23:02

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

Ответить
DrawMaster115
DrawMaster115 - 24.10.2023 23:24

Last Question, does anyone know if Button_UI has been replaced by just the Button class. Unity gives me a namespace error when I try to use Button_UI despite having the include UnityEngine.UI;

Ответить
DrawMaster115
DrawMaster115 - 24.10.2023 00:49

Does this solution allow for multiple overlapping audio clips? Is there any point in having and audio source component specific to each object that makes the noise?

Ответить
Snedden Gonsalves
Snedden Gonsalves - 22.10.2023 20:16

in the function playsound(), you instantiate a game object to attach a AudioSource component, is there a benefit to doing it like this rather than just adding a audioSource component to SoundManager entity and referencing that in Soundamanager.cs and using that again and again everytime the function gets called?

Ответить
paperplane011
paperplane011 - 14.10.2023 23:05

Thanks a lot man

Ответить
Hikrauda
Hikrauda - 03.08.2023 15:45

Works great! Only issue is that when the new sound object is instantiated it remains in the hierarchy, even after its played. Is there a way to destroy it easily after it plays if it's just a one-off sound?

Ответить
Mateo Osorio Cortes
Mateo Osorio Cortes - 28.06.2023 21:42

Do you know of a way to get the cover art of an audio file from a script to display it in a Sprite?

Ответить
Cristiano `
Cristiano ` - 08.03.2023 19:37

If anyone got ArgumentException, create folder named 'Resources' and add GameAssets prefab to it.

Ответить
Hakkology
Hakkology - 18.01.2023 10:09

Thank you for this great tutorial. Unfortunately, I get the error "The Object you want to instantiate is null".
I put my audio files inside a file called Resources/AudioAssets and wrote the following:
Instantiate(Resources.Load<AudioAssets>("AudioAssets"));

What am i doing wrong ? Does this only work with "GameAssets" ?
How does this code work actually ? How does it go to the assigned sound file exactly ? A bit more information would be very helpful.

Thanks for this tutorial. Regards,

Ответить
2020focus
2020focus - 01.11.2022 18:15

Could you make a tutorial on object pooling these sounds?

Ответить
hossein kardan
hossein kardan - 11.10.2022 10:57

what about a sound that repeats 1000 times? how do you deal with that extra 1000 gameObject that you created? you don't mention it at all

Ответить
N V
N V - 22.07.2022 20:57

As always amazing tutorial (I love your tutorials) - I think on this one though it didn't answer the "why build it" - why is it more efficient and better to have a sound manager? Sorry and hope it sounds like a complaint (is not really) But I always think it id good to know why an approach is needed and why to build something. - love your work a lot!!

Ответить
PawelDraws
PawelDraws - 22.07.2022 09:40

Consol shows me "NullReferenceException: Object reference not set to an instance of an object". Sound objects generate but no sound. What could be the reason?

Ответить
The Feesher
The Feesher - 30.05.2022 04:20

I cannot figure this out. Using this method, is there a way I can set different clips to have different component values??

I have audio that works essentially how I want, but I wanted to modify the code a bit, and it is just not working how I want, I hope the code explains enough. The if statement I isolated is the issue. I want the loop value to be true when the Level1Music clip is created.


if (CanPlaySound(sound))
{
GameObject soundGameObject = new GameObject("Sound");
soundGameObject.transform.position = position;
AudioSource audioSource = soundGameObject.AddComponent<AudioSource>();
audioSource.clip = GetAudioClip(sound);

Debug.Log(soundGameObject.GetComponent<AudioSource>().clip);





if (audioSource.clip.Equals(Sound.Level1Music))
{

soundGameObject.GetComponent<AudioSource>().loop = true;

}









audioSource.Play();

Object.Destroy(soundGameObject, audioSource.clip.length);
}
}

Ответить
CrispyBeans
CrispyBeans - 18.05.2022 19:42

Where the hell do you put the GameAssets thing on everything or what ????????????

Ответить
Fabian Obersovszky
Fabian Obersovszky - 18.05.2022 18:56

Isn't it better to create all audio sources for all sounds at the start? So dont need to create a new object everytime i want to play a sound. So it takes RAM instead of CPU.

Ответить
Matt Kern - Game Audio 1
Matt Kern - Game Audio 1 - 01.04.2022 23:32

Debug.Log(GameAssets.i.playerAttack); is null and Im not sure why.

Ответить
Ben Mora
Ben Mora - 06.02.2022 07:02

Won't this create a new GameObject in the scene every time you play a sound?

Ответить
michalski
michalski - 27.11.2021 02:48

Resources.Load<something>("smth") is null??

Ответить
Péter N.
Péter N. - 12.11.2021 01:02

wtf? class in class? you are creating a nightmare...

Ответить