2017-04-10 63 views
1

游戏重新启动罚款,如果你赢或输。玩家可以选择从这些场景中的任何一个回到标题屏幕。但是,暂停游戏并退出暂停菜单时会出现问题。如果你这样做,标题屏幕已加载,但没有音乐,也无法继续导航。出于某种原因,它确实允许您导航到乐谱(不带音乐)并返回到标题屏幕,但不能继续。顺序是,标题屏幕,教程屏幕,1级。我不知道它与它有什么关系,但显示的暂停菜单只是当您按空间时启用/禁用的画布。这是暂停脚本。退出暂停菜单重新开始从标题屏幕C#

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); 
} 

} 

回答

3

在:

if (!isPaused && Input.GetKeyDown (KeyCode.Escape)) 
{ 
    Application.LoadLevel ("titleScreen"); 

} 

    if (!isPaused) { 
     Time.timeScale = 0f; 
     pauseMenuCanvas.SetActive (true); 
     isPaused = false; 

     AudioListener.volume = 0f; 
    } 

当你检查,看看是否 “KeyCode.Escape” 被按下时,在 “titleScreen” 被加载,但下一行 “isPaused得到==真!”:

if (!isPaused)... 

转到“titleScreen”总是把音量为0时总是为真 AudioListener.volume = 0F;

+0

哦,确定它现在有效。谢谢! –