Player: Audio Management
After plenty of headaches with audio sources it seems that this solution is best option:
It’s possible to play multiple sounds at once with ONE Audiosource. You can play up to 10-12 audio sources at once (only) by using PlayOneShot(); With it, Unity mix the audio output from the audio clip into a single channel. (Which is why it’s limited to 10-12 clip at once.
The key here is ONLY USING ONESHOT(). The problem comes when using Play() and PlayOneShot() form the same AudioSource.
So the player in the glitch machine has 2 audio source – one for movement and one for SFX that can play simultaneously. The AudioSources are assigned in the Inspector
public AudioSource audioSourceMovement; public AudioSource audioSourceFX; /********************************************** MOVEMENT AUDIO (Audio Source 01) **********************************************/ if (!audioSourceMovement.isPlaying) { audioSourceMovement.volume = 0.05f; audioSourceMovement.pitch = (float)(1.0f + (playerDistanceUp * 0.01) + (playerSpeed * 0.01f)); audioSourceMovement.clip = moveAudio; audioSourceMovement.Play(); } /*********************************** FX AUDIO (Audio Source 02) ***********************************/ if (!audioSourceFX.isPlaying) { audioSourceFX.pitch = 1f; audioSourceFX.volume = 0.2f; if (isBoosting) { audioSourceFX.PlayOneShot(boostAudio); } if (playerMovement.current_Power <= 0) { audioSourceFX.PlayOneShot(outOfPower); } //etc......etc.........