Why won't my second Audio Source play?
import UnityEngine.SceneManagement;
#pragma strict
var maxFallDistance = -50; var audio1: AudioSource; var audio2: AudioSource;
function Start () { var aSources = GetComponents(AudioSource); audio1 = aSources[0]; audio2 = aSources[1];
if (transform.position.y > maxFallDistance) { audio1.Play(); }
}
function Update () {
if (transform.position.y <= maxFallDistance)
{
audio1.Stop();
}
if (transform.position.y <= maxFallDistance)
{ audio2.Play(); } }
I wanted one song to play normally, while the other one only plays when my player falls. But when I run it and my player falls, it's just silence. I know the problem isn't the AudioSource. But how do I get audio2 to play?
Could it be that your audioclips are 3D sounds? so if your audiosources are far from your listener (on camera by default), you won't hear some of them.
Your answer
Follow this Question
Related Questions
Audio Clip Error. 2 Answers
Playing multiple audio clips 2 Answers
Audio won't play, no matter what code or method I try 0 Answers
oneshot not working 0 Answers
How to reduce delay when playing sound 0 Answers