Unity Simple Audio Manager #1 - Switching Music Tracks

Unity Simple Audio Manager #1 - Switching Music Tracks

gamesplusjames

8 лет назад

39,673 Просмотров

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


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

TheFoof
TheFoof - 09.08.2023 07:53

7 years later and still incredibly insightful. Thank you, this is helping a lot.

Ответить
Richard Starkweather
Richard Starkweather - 23.04.2023 01:20

Thanks for this. Found it just in time for a project I was working on. While I had to tweak it for my application, the practical example showed me exactly what I needed.

Ответить
Elof Johansson
Elof Johansson - 09.03.2023 16:36

Thank you very much british man!!!!

Ответить
Bruce Wayne
Bruce Wayne - 10.07.2022 16:06

Very Smart way to do it

Ответить
yoursempai.
yoursempai. - 06.02.2022 23:16

the music is not switching please help

Ответить
OnceThereWasAPageWithAReallyLongAssNameAndNowYouAreLookingAtAChannelWithAReallyLongName!
OnceThereWasAPageWithAReallyLongAssNameAndNowYouAreLookingAtAChannelWithAReallyLongName! - 11.08.2021 17:12

Lovely when one thing stops you from making it work. I'm getting the "the type or namespace is missing 'Audio Manager'". In the SwitchAudioTrigger script.

Ответить
Fabrizio Alvarado
Fabrizio Alvarado - 27.05.2021 06:20

Bro u did everything i need, thank you!

Ответить
TinyPizza
TinyPizza - 17.05.2021 11:22

does anyone know how to change the music track back to the original

Ответить
Alberto Zapata
Alberto Zapata - 14.12.2020 06:51

Thank you so much! I was able to implement this to changing my BG music to a Boss Music

Ответить
Kradov Gamer
Kradov Gamer - 04.11.2020 23:15

MUITO FODA AJUDOU MUITO
MUITO OBRIGADO AJODOU MUITO
VC É FODA AJODIU SUITO

Ответить
KotManufa*ktur
KotManufa*ktur - 20.07.2020 22:06

4 everyone doin similar code and still havin problems ... try tag Player as Player ;)

Ответить
Marenka Sandoval
Marenka Sandoval - 19.07.2020 18:46

thank you very much this really help me

Ответить
Friedec
Friedec - 09.05.2020 20:42

if i want the music changing blendedly, i cant use this

Ответить
Ezequiel Torres
Ezequiel Torres - 15.02.2020 08:24

Thank you very much!!! Its Amazing!

Ответить
Rewind Arcade
Rewind Arcade - 18.06.2019 22:11

Incredibly helpful and easy to understand. Thanks for putting this together!

Ответить
xProMusje
xProMusje - 11.05.2019 18:30

thank you!

Ответить
Roy [Random Precision Software]
Roy [Random Precision Software] - 18.04.2019 21:29

Love it..Thanks

Ответить
Dan Iel
Dan Iel - 29.07.2018 13:02

Hmm I don't know about this, I would probably prefer to have every music track be represented by a bool in the music manager. Then you could just reference the music manager and activate/deactivate bools to start playing the music you want. Then you'll have all the music tracks listed neatly in the manager. Then a function to be called from the music manager to fade in or fade out music.

bool snowyVillage;
audioClip snowyVillage;
GameObject BGMObject;
audioSource BGM;

void Awake()
{
BGMObject = GameObject.FindWithTag("Music");
BGM = mainMenuMusic.GetComponent<AudioSource>();
}

void Update()
{
if(snowyVillage){
BGM.clip = snowyVillage;
}
}

void fadeIn()
{
BGM.volume -= 0.28f * Time.deltaTime;
}

More or less something like this?

Ответить
Fupicat
Fupicat - 01.04.2018 23:56

Very helpful! Thank you!

Ответить
Kabir Hamidi
Kabir Hamidi - 27.03.2018 20:00

to khely guy kho mokhry

Ответить
WipesDani GD
WipesDani GD - 18.02.2018 10:54

I have a problem:

I made the exact same thing as you did, but it doesn't work. If I want to make "private AudioManager theAM;" Unity doesn't know the word "AudioManager" so I can't do anything.

The only difference is that I have other variable names and in the menu script (the script for changing the scene) the functions for changing and 1 function so the screen fades in. I only want the music to change when I press the "Credits" button, but when I press the other 2 buttons the music should continue.

I have the newest Unity Engine (2017.3.1)

Please help me

Ответить
Reza Brilliansah
Reza Brilliansah - 30.01.2018 16:57

How do I make it so the audio does not play in a specific scene? I've been struggling for a while.

Ответить
Joshua Reyes
Joshua Reyes - 24.12.2017 02:15

Thank you I am implementing your logic in my upcoming game! Great work, clean code.

Ответить
christian allen coronel
christian allen coronel - 17.04.2017 12:45

its like switching music but the other music is in the other scene

Ответить
christian allen coronel
christian allen coronel - 17.04.2017 12:43

can you tell me how to pause sound that is from the other scene when i play sound..?
i want to get the audio source of the sound that goes throughtout the game and pause it to make other sound play and resume afetr

Ответить
BACKDOWN The Revenge
BACKDOWN The Revenge - 30.03.2017 13:40

Jpe yp fp yjod yp foggrtrmy dvrmd

Ответить
ReyGeeK Gilboy
ReyGeeK Gilboy - 17.11.2016 01:34

what can i do if I'm using the unity engine UI I'm not a programmer but I'm trying to do the switch track when you push a 2d button?

Ответить
Artem Kashkou
Artem Kashkou - 28.04.2016 16:07

hi James, do u know something about android audio latency? I discovered that if I for example put a Ui button on scene then play audio pressing this button, so on pc everything works good, but on Android I hear sound after maybe 0.1 second still I press it, don't u know how to solve this problem not using other plugins? thanks for that!
and sorry if my English is not perfect

Ответить
Alen Loeb
Alen Loeb - 28.04.2016 12:25

One question. Are you using Unity 5.3 because ontriggerenter2d does not work in newest version

Ответить
Erlandas Pilypas
Erlandas Pilypas - 27.04.2016 20:08

Thanks for the video! this will be useful

Ответить