Hey guys,
So I am trying to play a AudioSource only if a variable from another script is true/false. I tried to search the internet, but sadly nothing did help.
EDIT: DID solve the problem with bool of another script but audio will not play yet D:
using UnityEngine;
using System.Collections;
public class AudioManager : MonoBehaviour {
public AudioSource GameMusic; //Music playing while game is running
public AudioSource PauseMusic; //Music playing while paused
private GameObject _pause;
//Reference to the PauseMenu GameObject to get the paused bool out of it
AudioSource[] audios = new AudioSource[2];
// Use this for initialization
void Awake ()
{
audios[0]= GameMusic;
audios[1]= PauseMusic;
}
// Update is called once per frame
void Update ()
{
if(_pause != null)
{
if (!_pause.GetComponent<PauseMenu>().paused)
{
audios[1].Stop();
audios[0].Play();
}
else if (_pause.GetComponent<PauseMenu>().paused)
{
audios[0].Stop();
audios[1].Play();
}
}
else
{
_pause = GameObject.FindGameObjectWithTag("Pause");
}
}
}
The other Script is named “PauseMenu”.
I sitll have a problem when trying to play the musc D:
Hope you guys can help me out because I am stuck D: