Hey guys.
I’m using the default FPSController, and I’ve imported my own sounds to use for walking and jumping and stuff. It all works fine, except that the sound that’s played when landing is stopped if the player walks before it fully plays, with the footstep audio cutting it off. Is there some way to change a setting or tweak the code so that the landing sound is played to its end even as the footsteps are playing?
They must all be using the same audiosource.
An audiosource can only play 1 sound at a time, so if you play a new sound with an audiosource that is still busy playing a sound, the sound that is already playing is cut off.
The quick and ugly way to get around this, is for you to always play your landing sound through its own specific audiosource, and not use the same one as the stepping sounds.
The better option to solve this kind of problem is to have an array of audiosources (a pool), and then you play all your related sounds through that pool. You do this by assigning and playing clips only through audiosources that aren’t already playing sounds.
The amount of audio sources you would need depend on how many sounds could potentially be playing at the same time. That way you could also have your stepping sounds overlap, if they are particularly long sounds, like splashing through water or wading through thick grass or something.
Just to add to this a little to this good answer above, there’s also a function for AudioSource, PlayOneShot. PlayOneShot won’t interrupt other sounds played this way on a particular audio source, but you don’t have as much control over them like playing them normally, I believe. For some stuff it might work well though (ex. for something where the sound can play without having to stop short). You can set up an audiosource just for your one shot sounds, and then x # of audiosources for stuff that has to use the play() (or other) function to play.
As someone else found out in another thread, sounds played with Play() apparently will interrupt sounds played via PlayOneShot() on the same audio source though.
Myself, I do a combination of the “PlayOneShot” method and what Na-ra-ku described.