4
\$\begingroup\$

I've started using Unity recently and have ran into some snags with the built audio features. I am trying to have multiple sounds play from the Player Game Object. I'm not sure what the best way to do this.

I have looked into solutions that involve changing the audio clip in the audio source. The problem I ran into with this method was that using the function "PlayOneShot" allows the sounds to stack. So if I try using this method for the walking noise it creates a new instance of that sound that layers on top of each other each frame the player walks. I figure I need to make just a player noise track that starts and stops depending on when the player is walking.

I've also considered trying to use multiple audio sources on the game object.

I'm really not sure what the best approach is for this and I'm having a hard to finding resources in this subject area.

\$\endgroup\$
1
\$\begingroup\$

You need audio source component to use audio clip.

From getting that component you can access to PlayOneShot() function.

The best way to sync play the walking sound is to call an event from animation. Whenever the walking animation is making the legs touching ground call a public function from there which has PlayOneShot() in it.

enter image description here

\$\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.