Question by
jessicacasey · Oct 20, 2020 at 02:34 PM ·
audiosoundaudiosourceaudioclip
Some sounds won't play
The game I'm working on plays different sounds depending on what's going on. This is the script that decides what sound will play:
public AudioClip lightSwitch;
public AudioClip ticking;
public AudioClip winSound;
public AudioClip loseSound;
public AudioSource source; // The object that will play the sounds
void Start()
{
source.GetComponent<AudioSource>();
source.clip = lightSwitch;
source.Play();
Debug.Log("Playing lightSwitch");
}
void Update()
{
if(MGSystem.singelton.play == true)
{
source.clip = ticking;
source.Play();
Debug.Log("Playing ticking");
}
else
{
if (MGSystem.singelton.hasWon == true)
{
// hasWon is true when the game starts, so this makes sure the game has ended before playing the sound
if(MGSystem.singelton.secondsLeft == 0)
{
source.clip = winSound;
source.Play();
Debug.Log("Playing winSound");
}
else
{
return;
}
}
else
{
source.clip = loseSound;
source.Play();
Debug.Log("Playing loseSound");
}
}
}
The problem is that lightSwitch and winSound will play but ticking and loseSound won't. The debug log will pop up in the console so I know the code itself works, but for some reason those two clips won't play. Does anyone know what I'm doing wrong?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613014204im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Second AudioClip won't play 0 Answers
Second AudioClip won't play 0 Answers
Audio is way too soft on mobile but alright in Unity Editor! 0 Answers
Audio Cutting Out Unexplainably 1 Answer
Cracking at end of audio? 0 Answers