示例#1
0
    public void GameOver()
    {
        scoreText.text     = scoreText.text + string.Format("{0:0}", Score.score);
        highScoreText.text = highScoreText.text + string.Format("{0:0}", Score.highScore);

        gameOverMenu.SetActive(true);
        Time.timeScale = 0f;

        AudioSource audioSouce = FindObjectOfType <PlayerDeath>().GetComponent <AudioSource>();

        audioSouce.Stop();
        if (Score.score == Score.highScore)
        {
            audioSouce.clip = highScoreClip;
        }
        else
        {
            audioSouce.clip = gameOverClip;
        }
        BackgroundMusic bgMusic = FindObjectOfType <BackgroundMusic>();

        bgMusic.GetComponent <AudioSource>().volume = 0.2f;
        audioSouce.loop = true;
        audioSouce.Play();
    }
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
         instance.GetComponent <AudioSource>().Play();
     }
     DontDestroyOnLoad(instance.gameObject);
 }