Hello everyone,
I have a problem to stop my Pause Menu Music and reactivate the background Music of my Game. The background music stops after using “Escape” and the Pause Menu Music starts to play. But the Pause Menu Music don’t stop after using the “Resume” button or “Escape” and the background music also don’t start to play.
This is my script to manage the background music:
public GameObject Canvas;
public AudioSource background;
public AudioSource gameOver;
void Start()
{
background.Play();
}
void OnCollisionEnter2D(Collision2D c)
{
if (c.gameObject.tag == "Enemy" || c.gameObject.tag == "Bullet")
{
Canvas.SetActive(true);
Time.timeScale = 0;
background.Stop();
gameOver.Play();
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (background.isPlaying)
background.Stop();
}
}
and this is my script to manage the PauseMenu and “Resume” Botton:
public GameObject Canvas;
private bool _isShowing;
public AudioSource pauseMusic;
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
PauseGame();
}
}
public void PauseGame()
{
_isShowing = !_isShowing;
Canvas.SetActive(_isShowing);
pauseMusic.Play();
Time.timeScale = _isShowing ? 0 : 1;
}