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 BrodyDaChappy · Jan 30, 2016 at 10:29 PM · scorescore systemlevelslevel load

Updating Score on Level Change

HI All,

I am having a little trouble with updating the score from level_1 to level_2,

My aim is, once max level points have been reached on level_1 (750) then level_2 loads and the score carries over to level_2(750),

The problem is, when i gain 750 in level_1, level_2 loads fine the 750 points are shown and once the level starts it automatically gains 60 points so the application.loadlevel should stop once i have gone passed 750, as soon as level_2 loads the new score should be 810, it works but still level_2 keeps loading over and over as if i still have 750 points.

My question is how can i stop level_2 from loading over and over again?

here is my script, any ideas?

public class LevelManager : MonoBehaviour {

 public LevelManager levelManager;
 public int score;
 public int currentLevel
 public int Score=30;
 

 private PlayerController player;

 // Use this for initialization
 void Start () {
     player = FindObjectOfType<PlayerController>();
     if (Application.loadedLevelName == "Level_1") {
         score = 0;
         saveScores();
     } else {
         score = getSavedScores();    
     }  

 }

// Update is called once per frame void Update ()

 {  
     
     saveScores();
     changeLevel();
 }
 
 public void changeLevel()
 {
     if (score >= 750 && currentLevel == 1) 
     {

         saveScores();
         currentLevel++;
         Application.LoadLevel("Level_2");
 
     }    
     if(Application.loadedLevelName == "Level_2")
     {
         getSavedScores();    
     }
     
 }
 //possible if the save functionality intreacts with this
 public void saveScores()
 {
     if (score >= 750)
     {
         // setting the score
         PlayerPrefs.SetInt("Score", score);
         
     }
 }
 public int getSavedScores()
 {
     
     int tempScore = PlayerPrefs.GetInt("Score");  
     
     return tempScore;
 }
 
 
 public  int getScore()
 {    
     
     
     return score;
 }
 public void AddPoints(int points)
 {
     score += points;
 }

 void OnGUI()
 {
     GUILayout.Label(score.ToString());
 }

 void OnTriggerEnter2D(Collider2D other)
 {
     if(other.name == "Player")    
     
     {
         Application.LoadLevel(0); //this is on death completely restart game
     }


 }

}

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

1 Reply

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

Answer by GeoDragn · Jan 31, 2016 at 12:02 AM

From what I understand your game is checking if your score is equal to or higher than 750. Replace the larger than symbol with an equals sign.

So this

  if (score >= 750 && currentLevel == 1) 
  {
      saveScores();
      currentLevel++;
      Application.LoadLevel("Level_2");
 
  }   

Turns into this

  if (score == 750 && currentLevel == 1) 
  {
      saveScores();
      currentLevel++;
      Application.LoadLevel("Level_2");
 
  }   

Don't forget to do it throughout the whole script.

Comment
Add comment · Show 2 · 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 BrodyDaChappy · Jan 31, 2016 at 08:58 PM 0
Share

Thanks i made those changes, it didn't work at first but i forgot that i needed to also change it in my add points script :P silly me.

Thanks very much i appreciate the help.

avatar image GeoDragn BrodyDaChappy · Feb 01, 2016 at 09:32 PM 0
Share

you're welcome :)

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

41 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

Related Questions

Activate an animation when a certain score reached 0 Answers

How does one reference a UI instance from a prefab? 1 Answer

Score does not increment correctly 0 Answers

How do I add a score system? 1 Answer

How can i get the value of the Scrpit what is attached on the Image 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