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 /
avatar image
0
Question by Wolfdog · Apr 12, 2015 at 03:17 PM · c#script.unity5

Call function once in a while after a condition is met?

I want to grant the player one extra life every 10000 points.

 void extraLife (){
     PlayerPrefs.SetInt ("Lives", PlayerPrefs.GetInt("Lives") + 1);
 }
 

I keep the player's score in PlayerPrefs.Getint ("Score");

The player's score doesn't increase in steady amounts - it increases in 10s, 200s and 500s.

How do I call the function extraLife() once the 10,000 limit has been crossed, but only once, until the limit is broken again?

For example, the player has 10,210 points. I want to grant him a life. When he reaches 20,000, I want to grant him another life. But the player won't have exactly 20,000 points, but a bit more. How do I do this?

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
2
Best Answer

Answer by DoTA_KAMIKADzE · Apr 12, 2015 at 03:30 PM

Well you could do something of those:

1) If your progression is linear then just add another int variable and a constant of progression. How will that work? Well just when each time score increases check like this:

 if (score >= progressionConstant * currentProgressionInteger)
 {
     currentProgressionInteger++;
     extraLife();
 }

Also don't forget to save that currentProgressionInteger.

2)If non-linear. Then you might have to add a for example a List or array of "progression bases" for which your player will be rewarded, and then do almost the very same thing (except that this time progressionConstant will be replaced with a List/Array/Dictionary/...):

 if (score >= progressionList[currentProgressionInteger])
 {
     currentProgressionInteger++;
     extraLife();
 }
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 Wolfdog · Apr 12, 2015 at 05:59 PM 0
Share

Thank you.

avatar image MajorParts · Jun 03, 2015 at 05:56 PM 0
Share

I did post an alternative way of awarding an extra life every x amounts of points, but apparently one answer is enough for such an "ancient" question! Sorry to anyone co$$anonymous$$g here who doesn't understand the "allowed" answer and might've benefited from $$anonymous$$e.

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

19 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

Related Questions

How to define a slider on script file? 1 Answer

Multiple Cars not working 1 Answer

How to launch built-in/first party applications using c# in Unity project (for both Android and iOS)? 0 Answers

Distribute terrain in zones 3 Answers

How to keep the old line text? 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