Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question One AudioSource per AudioClip?

Discussion in 'Audio & Video' started by RageByte, Mar 14, 2021.

  1. RageByte

    RageByte

    Joined:
    Jul 2, 2017
    Posts:
    33
    Say you have an object and you want to play several different sounds clips from this object. Should I add an AudioSource per each AudioClip I want to play? Or can I play the AudioClips all from one AudioSource? And if so, will they cut each other off if played simultaneously (very tightly one after the other)?

    Any help is appreciated.

    [Edit]: Pretty sure I already know the answer. Just looking for validation.
     
    Last edited: Mar 15, 2021
  2. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    137
    Hi, so if you want to play multiple sound effects from a single Audio Source you can do that with Play One Shot.

    This will work without cutting off any previous sound already playing on the Audio Source. This is good for sound effects mostly, but the drawback is you lose the ability to loop.

    The Audio Source's settings (like pitch, 3d placement etc.) will apply to all sounds is playing from the Audio Source but volume can still be controlled from Play One Shot, where you have the option of playing the sound at a scaled volume, relative to the volume of the Audio Source.

    For more, I wrote an in-depth guide that you might find useful here: https://gamedevbeginner.com/how-to-play-audio-in-unity-with-examples/

    Hope that helps.
     
  3. RageByte

    RageByte

    Joined:
    Jul 2, 2017
    Posts:
    33
    Thanks for the reply JLF. What's funny is I found your Unity audio guide yesterday and used it to write my audio script! Thanks again.
     
    JLF likes this.
  4. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    137
    Ha, no problem glad it helped!