0
\$\begingroup\$

I just learned how to implement a Sound Manager and put sounds into it. The problem is, I'm making a platformer and I have a player, and two different types of enemies who all have footstep sounds. The main issue is that I'm playing all the sounds from the same sound manager and I made the footstep sounds of the player to play like this:

  public void PlayMoveSound()
{   
    if(audioSrc.isPlaying == false)
    {
    randomMoveSound = Random.Range(0,5);
    audioSrc.PlayOneShot(moveSounds[randomMoveSound]);  
    }
}

I don't know how else to make it NOT sound like its playing 100 times per second so I did this. This gave birth to the issue that the looping audio which is the player's movement sound now blocks me from doing the same thing for the other characters' footstep sounds since it uses the same "audioSrc" AudioSource. Any hints on how different I can create a system for semi-looping audio?

\$\endgroup\$
3
  • \$\begingroup\$ I personally prefer to make footstep sounds part of the walk animation. This way the sound repeat speed is always automatically tied to the speed of the walking animation and they are always in perfect sync. You can search google for "unity animation events", they are basically method calls at specific point during an animation. \$\endgroup\$ – Nikaas Oct 4 '20 at 10:56
  • \$\begingroup\$ @Nikaas thanks mate, I'll look into that. Didn't know such a thing existed. \$\endgroup\$ – Scott Weiland Oct 4 '20 at 11:04
  • \$\begingroup\$ Footsteps are an odd choice to run through a centralized manager. Usually we'd play them through an audio source on each character's model/sprite, so they get correct spatialization (eg. panning the sound left when the character is on the left side of the screen) \$\endgroup\$ – DMGregory Oct 4 '20 at 12:45
1
\$\begingroup\$

A single Sound Manager is good for non-diegetic sounds like background music or interface sounds. It is usually not so good for diegetic sounds emitted by entities actually present in the game world.

When you want to add footsteps to a game object, then it's usually the better choice to add those footsteps as an audio source to that game object. The neat advantage of this is that this makes the sounds directional. So objects on the left side of the screen are louder on the left speaker while those on the right side are louder on the right speaker. This increases the grade of immersion of your game.

You should also use a separate audio source for every sound effect an entity can make. This prevents conflicts between looping and non-looping effects like you experience them right now. It also allows you to tune the audio source settings of each sound effect individually and send different sounds to different inputs of your audio mixer.

When you need to control those audio sources via script, then that controller script should be attached to the same game object as the audio sources.

But note that the Unity animation system can also be used for controlling audio sources. So when you are already using an animation controller, then you might have the walk animation control the footstep audio source as well.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.