Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by JJNCreator · Aug 26, 2012 at 12:37 PM · saveloadscoreleveladjust

Score system Level Load

Hey guys. I have a score script (attached to the player) that gives the player a point or 2 each time they beat an enemy. However, I have more than one level and when I load a new level, it resets the score. Here's the script:

 using UnityEngine;
 using System.Collections;
 
 public class ScoreCount : MonoBehaviour {
     public int maxScore = 15;
     public int curScore = 0;
     
     
     void Awake() {
     }
     
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         AddjustCurrentScore(0);
     
     }
     
     void OnGUI() {
         GUI.Box(new Rect(1075,10,90,20),"Score:" + curScore + "/" + maxScore);
     }
     
     public void AddjustCurrentScore(int adj) {
         curScore += adj;
         
         if(curScore < 0)
             curScore = 0;
         
         if(curScore > maxScore)
             curScore = maxScore;
         
         if(maxScore < 1)
             maxScore = 1;
         
     }
 }


Is there a way I could have the score count save when I load a new level. Thanks!

(If post doesn't appear right, please edit)

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

Answer by DragonSaige · Aug 26, 2012 at 03:24 PM

Sounds confusing. If you don't manually change your score it will stay the same even after you load another level. Also , I have a look at the script where you placed your application.loadlevel();.

Comment
Add comment · Show 4 · 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 JJNCreator · Aug 26, 2012 at 03:46 PM 0
Share

I haven't done that yet, but if I did, I would use this code:

ScoreCount sc = (ScoreCount)_player.GetComponent("ScoreCount"); sc.AddjustCurrentScore(+2); if(sc.curScore == 15) { Application.LoadLevel(levelindex);

avatar image DragonSaige · Aug 26, 2012 at 04:24 PM 0
Share

I'm still not very sure why you are switching to next scene when all you want is to spawn enemies. I'd rather do

if(sc.curScore == maxScore) { level++; maxScore +=15; }

and then in enemy script multiply speed,spawnCount by level. this will make your score consistent and you won't have to go through the trouble of switching scenes. hope it helps

avatar image DragonSaige · Sep 20, 2012 at 12:17 PM 0
Share

Okay, I finally understand what you were trying to do; Here's how: 1. $$anonymous$$ake a object, say x, that'll hold all the variables from your level 1. 2. Apply DontDestroyOnLoad() function on x. 3. Load new level, then use x to get all the values back.

avatar image DragonSaige · Sep 20, 2012 at 12:19 PM 0
Share

PlayerPrefs may also be used in this case.

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

8 People are following this question.

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

Related Questions

PlayerPrefs 2 Answers

Saving score to next level? 3 Answers

Score and Level Loading 1 Answer

checkpoint level please 2 Answers

how to make a level load after hitting a score 1 Answer


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