Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by klondyke · Mar 29, 2018 at 06:16 AM · resetquit

How do I get my Quit button to reset the score?

Hi - When I restart the game using the Quit button, it doesn't reset the scores and lives? What am I doing wrong? I included my Gameplay Controller and Game Manager script below. How do I get my Quit button to reset the score? Thank you for any help!

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.SceneManagement;
 
 public class GameManager : MonoBehaviour {
 
     public static GameManager instance;
 
     [HideInInspector]
     public bool gameStartedFromTitleScene, gameRestartedAfterPlayerDied;
 
     [HideInInspector]
     public int score, coinScore, lifeScore;
 
     void Awake () {
         MakeSingleton ();
     }
 
     void Start() {
         InitializeVariables ();
     }
 
 
     void OnEnable() {
         SceneManager.sceneLoaded += LevelFinishedLoading;
     }
 
     void Disable() {
         SceneManager.sceneLoaded -= LevelFinishedLoading;
     }
 
     void LevelFinishedLoading(Scene scene, LoadSceneMode mode) {
         if(scene.name == "GameplayScene") {
 
             if(gameRestartedAfterPlayerDied) {
 
                 GameplayController.instance.SetScore(score);
                 GameplayController.instance.SetCoinScore(coinScore);
                 GameplayController.instance.SetLifeScore(lifeScore);
 
                 PlayerScore.scoreCount = score;
                 PlayerScore.coinCount = coinScore;
                 PlayerScore.lifeCount = lifeScore;
 
             } else if(gameStartedFromTitleScene) {
                 PlayerScore.scoreCount = 0;
                 PlayerScore.coinCount = 0;
                 PlayerScore.lifeCount = 2;
 
                 GameplayController.instance.SetScore(0);
                 GameplayController.instance.SetCoinScore(0);
                 GameplayController.instance.SetLifeScore(2);
 
             }
         }
     }
 
     void InitializeVariables() {
         if (!PlayerPrefs.HasKey ("Game Initialized")) {
             
             GamePreferences.SetEasyDifficultyState(1);
             GamePreferences.SetEasyDifficultyCoinScore(0);
             GamePreferences.SetEasyDifficultyHighscore(0);
 
             GamePreferences.SetMediumDifficultyState(0);
             GamePreferences.SetMediumDifficultyCoinScore(0);
             GamePreferences.SetMediumDifficultyHighscore(0);
         
             GamePreferences.SetHardDifficultyState(0);
             GamePreferences.SetMediumDifficultyCoinScore(0);
             GamePreferences.SetHardDifficultyHighscore(0);
 
             GamePreferences.SetMusicState(0);
 
             PlayerPrefs.SetInt("Game Initialized", 123);
         
         }
 
     }
 
     void MakeSingleton() {
         if(instance != null) {
             Destroy(gameObject);
         } else {
             instance = this;
             DontDestroyOnLoad(gameObject);
         }
     }
 
     public void CheckGameStatus(int score, int coinScore, int lifeScore) {
 
         if(lifeScore < 0) {
 
             if (GamePreferences.GetEasyDifficultyState() == 1) {
 
                 int highScore = GamePreferences.GetEasyDifficultyHighscore();
                 int coinHighScore = GamePreferences.GetEasyDifficultyCoinScore();
 
                 if (highScore < score)
                     GamePreferences.SetEasyDifficultyHighscore(score);
 
                 if (coinHighScore < coinScore)
                     GamePreferences.SetEasyDifficultyCoinScore(coinScore);
 
             }
 
             if (GamePreferences.GetMediumDifficultyState() == 1) {
                                 
                 int highScore = GamePreferences.GetMediumDifficultyHighscore();
                 int coinHighScore = GamePreferences.GetMediumDifficultyCoinScore();
                                 
                 if (highScore < score)
                     GamePreferences.SetMediumDifficultyHighscore(score);
                                 
                 if (coinHighScore < coinScore)
                     GamePreferences.SetMediumDifficultyCoinScore(coinScore);
                                 
             }
 
             if (GamePreferences.GetHardDifficultyState() == 1) {
                                 
                 int highScore = GamePreferences.GetHardDifficultyHighscore();
                 int coinHighScore = GamePreferences.GetHardDifficultyCoinScore();
                                 
                 if (highScore < score)
                     GamePreferences.SetHardDifficultyHighscore(score);
                             
                 if (coinHighScore < coinScore)
                     GamePreferences.SetHardDifficultyCoinScore(coinScore);
                                 
             }
 
             gameStartedFromTitleScene = false;
             gameRestartedAfterPlayerDied = false;
 
             GameplayController.instance.GameOverShowPanel();
 
         } else {
 
             this.score = score;
             this.coinScore = coinScore;
             this.lifeScore = lifeScore;
 
 //            GameplayController.instance.SetScore(score);
 //            GameplayController.instance.SetCoinScore(coinScore);
 //            GameplayController.instance.SetLifeScore(lifeScore);
 
             gameStartedFromTitleScene = false;
             gameRestartedAfterPlayerDied = true;
 
             GameplayController.instance.PlayerDiedRestartTheGame();
         }
 
     }
 
 } // GameManager


 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class GameplayController : MonoBehaviour {
 
     public static GameplayController instance;
 
     private AudioSource audioManager;
 
 //    [SerializeField]
 //    private AudioClip deadClip;
 
     [SerializeField]
     private Text scoreText, coinText, lifeText;
 
     [SerializeField]
     private GameObject pausePanel, gameOverPanel;
 
     [HideInInspector]
     public bool countScore;        
 
 
     void Awake () {
         MakeInstance ();
         Time.timeScale = 0f;
         audioManager = GetComponent<AudioSource> ();
 
     }
 
     void Start() {
     }
     
     void MakeInstance() {
         if(instance == null) {
             instance = this;    
         }
     }
 
     public void GameOverShowPanel() {
         gameOverPanel.SetActive (true);
 //        audioManager.clip = deadClip;
 //        audioManager.Play ();
 
     }
 
     public void PlayerDiedRestartTheGame() {
         StartCoroutine(PlayerDiedRestart ());
     }
 
     IEnumerator PlayerDiedRestart() {
         yield return new WaitForSeconds (1f);
 //        SceneManager.LoadScene ("GameplayScene");
         SceneFader.instance.LoadLevel ("GameplayScene");
     }
 
     public void SetScore (int score) {
         scoreText.text = " " + score;
     }
 
     public void SetCoinScore (int coinScore) {
         coinText.text = " " + coinScore;
     }
  
     public void SetLifeScore (int lifeScore) {
         lifeText.text = " " + lifeScore;
     }
 
     public void PauseTheGame() {
         Time.timeScale = 0f;
         pausePanel.SetActive (true);
     }
 
     public void ResumeGame() {
         Time.timeScale = 1f;
         pausePanel.SetActive (false);
     }
 
 //    public void quit() {
 //        Debug.Log ("has quit game");
 //        Application.Quit;
 //    }
 
     public void ReStartGame() {
         Time.timeScale = 1f;
         PlayerScore.coinCount = 0;
         PlayerScore.scoreCount = 0;
         PlayerScore.lifeCount = 2;
 
         GameplayController.instance.SetScore(0);
         GameplayController.instance.SetLifeScore(2);
         GameplayController.instance.SetCoinScore(0);
         SceneFader.instance.LoadLevel ("TitleScene");
     }
 
 
 } //GameplayController
 

 
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

128 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Restart the application 0 Answers

how to reset ball function after 10 second of delay 0 Answers

Reset rotation of gameobject 1 Answer

Reset button in an one scene game 0 Answers

Application.Quit() won't work on iOS and screen does not auto lock while inactive 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges