Hello,
I can’t seem to get my audioclips to play at the same time without cutting each other off. As near as I can tell, every time an audioclip is played it is played through the same audiosource. I have three audiosources available for my SoundManager script to use, and I have tried to use audiosource.isPlaying to alternate between them; however, I set up a debug test in Start() in my PlayerController script where the game starts by playing three sounds in a row. The logs show the same audiosource being used and, of course, I only hear the one sound - but the logs also show each sound being played (before being “cut off”).
I am using Unity 5.6, but I had this issue in Unity 5.5 before I upgraded this week. Most of my sounds are triggered by collision between the player object and other gameobjects in the scene. In ordinary game play, the appropriate sounds play correctly on collision, but if the player collides with another object before the old sound completes the new sound is played and the old sound is abruptly stopped. I have tried both Play() and PlayOneShot() without any change.
Some of the relevant code:
-snipped from my SoundManager script which is called from PlayerController (below)
public class SoundManager : MonoBehaviour {
public AudioSource efxSource;
public AudioSource musicSource;
public AudioSource thirdSource;
public static SoundManager instance = null;
public float lowPitchRange = .95f;
public float highPitchRange = 1.05f;
// Use this for initialization
void Awake ()
{
if (instance == null)
instance = this;
else if (instance != null) {
Debug.Log ("destroying sound instance");
//Destroy (gameObject);
}
DontDestroyOnLoad (gameObject);
}
public void PlaySingle (AudioClip clip)
{
efxSource.clip = clip;
if (efxSource.isPlaying) {
PlayMajor (clip);
} else {
efxSource.Play();
Debug.Log ("***efxsource played");
}
}
public void PlayMajor (AudioClip clip)
{
musicSource.clip = clip;
if (musicSource.isPlaying) {
PlayThird (clip);
} else {
musicSource.Play();
Debug.Log ("***musicsource played");
}
}
public void PlayThird (AudioClip clip)
{
thirdSource.PlayOneShot (clip);
Debug.Log ("***thirdsource played");
}
-snipped from PlayerController
void Start ()
{
ended = false;
complete = false;
gameManager = Loader.FindObjectOfType<GameManager>();
soundManager = Loader.FindObjectOfType<SoundManager> ();
level = gameManager.getLevel ();
//test soundsources
soundManager.PlaySingle(bonusSound);
Debug.Log ("***sound 1 played");
soundManager.PlaySingle (powerUpSound);
Debug.Log ("***sound 2 played");
soundManager.PlaySingle (pickUpSound);
Debug.Log ("***sound 3 played");
And a record from my log in the editor:
It never seems to try SoundManager.PlayMajor().