- Home /
 
something is wrong with my code cant find out...i am a newbie
my GameManager script is
public class GameManager : MonoBehaviour {
 public static GameManager instance;
 [HideInInspector]
 public bool gameStartFromMainMenu, gameRestartedAfterPlayerDied;
 [HideInInspector]
 public int score, coinScore, lifeScore;
 void Awake () {
     MakeSingleton();
 }
 
 
               void OnEnable() { SceneManager.sceneLoaded += LevelFinishedLoading;
 }
 void OnDisable()
 {
     SceneManager.sceneLoaded -= LevelFinishedLoading;
 }
 void LevelFinishedLoading(Scene scene, LoadSceneMode mode)
 {
 
     if (SceneManager.GetActiveScene() == SceneManager.GetSceneByName("Gameplay"))
     {
         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 (gameStartFromMainMenu)
         {      
             PlayerScore.scoreCount = 0;
             PlayerScore.coinCount = 0;
             PlayerScore.lifeCount = 2;
             GameplayController.instance.SetScore(0);
             GameplayController.instance.SetCoinScore(0);
             GameplayController.instance.SetLifeScore(2);
         }                           
               
     }
 }
 // Update is called once per frame
 void MakeSingleton () {
     if (instance != null)
     {
                     Destroy(gameObject);
     }
         else
     {
         instance = this;
         DontDestroyOnLoad(gameObject);
     }
 }
 public void CheckGameStatus(int score, int coinScore, int lifeScore)
 {
     if (lifeScore < 0)
     {
         gameStartFromMainMenu = false;
         gameRestartedAfterPlayerDied = false;
         GameplayController.instance.GameOverShowPanel(score, coinScore);
     }
     else
     {
         this.score = score;
         this.lifeScore = lifeScore;
         this.coinScore = coinScore;
         GameplayController.instance.SetScore(score);
         GameplayController.instance.SetLifeScore(lifeScore);
         GameplayController.instance.SetCoinScore(coinScore);
         gameStartFromMainMenu = false;
         gameRestartedAfterPlayerDied = true;
         GameplayController.instance.PlayerDiedRestartTheGame();
     }
 }
 
               but when i use GameManager.instance.CheckGameStatus(scoreCount, coinCount, lifeCount);
in other scripts it give me an error ....pls can anyone help
What error do you get? $$anonymous$$aybe if we have more information we can help you.
Answer by bakir-omarov · Jun 11, 2018 at 09:12 AM
All is correct in code, at least MakeSingleton part will work, and you can call your void from anywhere like this. Can you explain error. I think you forgot to attach GameManager script to any GameObject on scene.
thax bro i was making the stupid mistake Game$$anonymous$$anager wasen't attached......as i said i am a newbie :P .....thax again bro
Your answer
 
             Follow this Question
Related Questions
Look On Cursor Problem 1 Answer
Setting a random animation frame from multiple animations 0 Answers
C# Children of GameObject has it's script disabled after SetActive(false) and SetActive(true) 1 Answer
My raycast wont function properly 0 Answers
How to create a score manager script involving awarding points from multiple objects? 2 Answers