Reputation: 115
The game restarts fine if you win or lose. The player has the option of going back to the title screen from either of those scenes. But the problem occurs when you pause the game and quit from the pause menu. If you do, the title screen is loaded but there is no music and no way to go navigate further. It does, for some reason, allow you to navigate to the credits (without music) and back to the title screen, but no further. The order is, title screen, tutorial screen, level 1. I don't know if it has anything to do with it, but the pause menu that shows is just a canvas that is enabled/disabled when you press space. Here's the pause script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class pauseScript : MonoBehaviour {
private bool isPaused = true;
public GameObject pauseMenuCanvas;
public AudioSource audioSource;
public AudioClip Paused;
public AudioClip notPressingStart;
void Awake ()
{
audioSource = GetComponent<AudioSource> ();
}
void Update ()
{
Sound ();
Pausing ();
}
void Pausing()
{
if (!isPaused && Input.GetKeyDown (KeyCode.Escape))
{
Application.LoadLevel ("titleScreen");
}
if (!isPaused) {
Time.timeScale = 0f;
pauseMenuCanvas.SetActive (true);
isPaused = false;
AudioListener.volume = 0f;
} else {
Time.timeScale = 1f;
pauseMenuCanvas.SetActive (false);
isPaused = true;
AudioListener.volume = 1f;
}
if (Input.GetKeyDown (KeyCode.Space)){
isPaused = !isPaused;
}
}
void Sound()
{
if (Input.GetKeyDown (KeyCode.Space))
audioSource.PlayOneShot (Paused, 7f);
}
}
Upvotes: 1
Views: 82
Reputation: 61
Within:
if (!isPaused && Input.GetKeyDown (KeyCode.Escape))
{
Application.LoadLevel ("titleScreen");
}
if (!isPaused) {
Time.timeScale = 0f;
pauseMenuCanvas.SetActive (true);
isPaused = false;
AudioListener.volume = 0f;
}
When you check to see if "KeyCode.Escape" is pressed while "!isPaused == true", the "titleScreen" is loaded but the next line:
if (!isPaused)...
will always be true when going to the "titleScreen" which always turns the volume to 0 AudioListener.volume = 0f;
Upvotes: 3