• 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 greystoke · Aug 22, 2010 at 03:47 PM · loadscorelevelpointsnext

open door to next level, after 10000 points were added to your score (solved)

ha ha, I will ask in t$$anonymous$$s way, to keep it simple.

How do you write t$$anonymous$$s in code (javascript)?

"open door to next level, after 10000 points were ADDED to you current score."

I don't know, how to check the score, if 10000 points were added.

T$$anonymous$$nk of a pinball-game with several levels. For example, you make 15692 points in the 1st level. Now you enter the 2nd level. The score of the 1st level is retained. Now, you must score another 10000 points for the 3rd level. So here, the minimum score has to be 25692 points for the 3rd level.

Any clever suggestions? :)


t$$anonymous$$s is my (simplified) code so far. It works for the 1st level, but NOT in the 2nd level, the door opens immediately. (I get the current score from another script).

private var levelscore : float;

private var nextlevelscore : float;

function Start(){

 nextlevelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;

}

function Update () {

 levelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;


 if(levelscore >= nextlevelscore + 10000) {
     animation.Play("Take 001");
 }

}


I save the current score points constantly in another script (SCORE).

PlayerPrefs.SetFloat("Player Score", scorePoints);

Only when the 1st level starts, the score ist set to 00000.


I found my solution. One problem was, that the score was set to 0 in another script, when loading the next level.

Another problem is, that the score is set to 0, when you declare a variable. Even, if you give that variable a certain number afterwards. (so the levelscore is $$anonymous$$gher than the nextlevelscore (0) for a millisecond, therefore the 'door' opens immediately in the 2nd level.)

private var nextlevelscore : float;

function Start(){ nextlevelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints; }

.

.

.

Finally, t$$anonymous$$s works:

private var levelscore : float;

private var nextlevelscore : float = PlayerPrefs.GetFloat("Player Score");

function Update () {

 levelscore = GameObject.Find("GAME").GetComponent(SCORE).scorePoints;

 if(levelscore >= nextlevelscore + 10000) {
     animation.Play("Take 001");
 }

}

(An extra script for the 1st level resets everyt$$anonymous$$ng back to 0.)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by e-bonneville · Aug 22, 2010 at 04:11 PM

Yup. When you enter a level, create a variable that contains the current score. (var originalScore = score) When your current score equals the original score + 10000 (if score = originalScore + 10000), open the door to the next level.

Does that work for you?

Comment
Add comment · Show 3 · 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 greystoke · Aug 22, 2010 at 04:32 PM 0
Share

thx for the answer, but it doesn't work in the 2nd level. The 'door' opens immediately, and not after another 10000 points. I don't understand, why?!

avatar image e-bonneville · Aug 23, 2010 at 03:22 PM 0
Share

You have to reset originalScore on entering every level to equal the current score.

avatar image e-bonneville · Aug 23, 2010 at 03:23 PM 0
Share

Don't increment it like the real score.

avatar image
0

Answer by StephenLTGAMES · May 12, 2011 at 02:42 PM

Save the old score (then call it after the level has loaded) Note would help with scripting if i could get own save /load to work.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

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

Score system Level Load 1 Answer

Score and Level Loading 1 Answer

OnLevelWasLoaded script problem. 1 Answer

enemies Scoring points killed 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