Question by
shepsaus000 · Jun 03, 2016 at 06:08 PM ·
scripting problemaudiobooleanchangefalse
boolean not switching to false.
I only want one song to play, and my code's boolean isn't switching to false when the appropriate code is executed:
using UnityEngine;
using System.Collections;
public class LevelMusic : MonoBehaviour {
public AudioSource audioSource;
public AudioSource audioSource1;
public bool playSongOnce;
public int audioDecider;
void Start(){
playSongOnce = true;
}
void Update () {
if (playSongOnce == true) {
PlaySound ();
}
}
void PlaySound (){
audioDecider = Random.Range (0, 2);
if (audioDecider == 0) {
audioSource.Play ();
playSongOnce = false;
return;
}
if (audioDecider == 1) {
audioSource1.Play ();
playSongOnce = false;
return;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612082222im_/https://answers.unity.com/themes/thub/images/avi.jpg)