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 /
avatar image
0
Question by sumitss · Jun 11, 2018 at 08:56 AM · scripting problem

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

Comment
Add comment · Show 1
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
avatar image The_Icaruz · Jun 11, 2018 at 09:40 AM 0
Share

What error do you get? $$anonymous$$aybe if we have more information we can help you.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 1 · Share
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
avatar image sumitss · Jun 11, 2018 at 09:55 AM 0
Share

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

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

150 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 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

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


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