2017-04-10 74 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

哦,確定它現在有效。謝謝! –

相關問題