Search Unity

Audio Audio issues with large number of audio sources

Discussion in 'Audio & Video' started by Eugene-B, Sep 2, 2017.

  1. Eugene-B

    Eugene-B

    Joined:
    Sep 7, 2014
    Posts:
    322
    Hello! Tell me please how to solve this kind of problem. When I place a lot of sounds on scene, I hear only cracking in my speakers. The sounds are played back by the PlayOneShot (). Thank you!
     
  2. schkorpio

    schkorpio

    Joined:
    Apr 15, 2015
    Posts:
    14
    You are likely playing the sound over and over in your update loop - so it's trying to play 60 times a second, and instead sounds like crackling.

    Use AudioSource.IsPlaying to check that the sound is not playing, so that it only plays once.
     
  3. MaeganEpps

    MaeganEpps

    Joined:
    Oct 23, 2018
    Posts:
    6
    Hey.Working with audio is hard work. I did it with these functions -
    public class gameSound : MonoBehaviour {
    public AudioClip audioClip = null;
    AudioSource audioClipSource = null;
    void Start(){
    audioClipSource = gameObject.AddComponent<AudioSource>();
    audioClipSource.clip = audioClip;
    audioClipSource.loop = true;
    audioClipSource.volume = 0.1f;
    audioClipSource.priority = 255;
    if(soundManager.Instance.isVolumeOn()) audioClipSource.Play();
    }
    void FixedUpdate(){
    if (!soundManager.Instance.isVolumeOn()){
    audioClipSource.Stop();
    }
    else if (!audioClipSource.isPlaying) audioClipSource.Play();
    }
    }