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 /
This question was closed Jul 22, 2018 at 05:45 PM by chiave15 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by chiave15 · Jul 22, 2018 at 04:17 AM · unity 5playerlevelcodepage

How to let player know they have completed a level

I have a game where all levels are unlocked, I need to let the user know that they have completed a level, they click on a button to switch to a level my game has 15 levels so I have this scriptalt text

The for loop is to check all the levels to see which levels have not been completed, if the level is not completed then the color is going to equal the color of a hidden button which is red alt text

The thing is...the system I created works like a regular unlock and lock system (play level 1 to unlock 2, play level 2 to unlock 3 etc.)

so let's say I play level 7 (remember all levels are unlocked) it will leave the buttons after 7 (8 - 15) the level not played color which is red, which I want it to do, but the buttons before 7 (1 - 6) will be there normal color, indicating that the player has played levels 1 through 6 but they haven't. I need a fool proof way of informing a user that they have completed a level, even if they go to level 7 with out playing levels 1 - 6 it will only show hat they have played level 6 and not the levels before 6 as well.

P.S. the PlayerPrefs.DeleteKey("LevelIsNotCompleted"); is so before I export my APK I delete any saved data I might have stored during the development process in the unity editor. @UnityCoach

@AnyoneElseThatCanHelp

bandicam-2018-07-21-22-28-44-308.jpg (73.5 kB)
bandicam-2018-07-21-22-40-50-442.jpg (42.4 kB)
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

  • Sort: 
avatar image
1
Best Answer

Answer by UnityCoach · Jul 22, 2018 at 02:09 PM

Hi,

If you have no more than 32 levels, you can store the completion as a bit array. In other words, a 32 bit integer of which every bit is used to store a boolean value.

 bool GetLevelCompleted (int level)
 {
     return PlayerPrefs.GetInt("LevelsCompleted") & (1 << level) != 0;
 }

 void SetLevelCompleted (int level)
 {
     PlayerPrefs.SetInt("LevelsCompleted", PlayerPrefs.GetInt("LevelsCompleted") | (1 << level));
 }

 void Init ()
 {
     for (int i = 0 ; i < buttons.Length ; i++)
         if (GetLevelCompleted(i))
             buttons[i].colors = grapfic.colors;
 }

Unless you really want to place the buttons manually, I would also use Layout components (Vertical, Horizontal or Grid), instantiate buttons through scripting, and assign listeners to buttons events automatically too.

Hope this helps.

Comment
Add comment · Show 13 · 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 chiave15 · Jul 22, 2018 at 03:27 PM 0
Share

Ok..... I have one more tiny problem alt text

@UnityCoach

bandicam-2018-07-22-10-21-51-088.jpg (99.0 kB)
avatar image UnityCoach chiave15 · Jul 22, 2018 at 03:31 PM 1
Share

I don't see the attachement. What is the problem ?

avatar image chiave15 UnityCoach · Jul 22, 2018 at 03:34 PM 0
Share

I just reposted it...look again @UnityCoach

Show more comments
avatar image UnityCoach chiave15 · Jul 22, 2018 at 03:50 PM 1
Share

Ah yes, I believe you have to put it this way then :

 return (PlayerPrefs.GetInt("LevelsCompleted") & (1 << level)) != 0;
avatar image chiave15 UnityCoach · Jul 22, 2018 at 04:09 PM 0
Share

Ok...Smh… ok one more thing unity is doing that I need to fix, the code above is correct but unity is throwing this error in my face like a pound of crap lol

@UnityCoach alt text

bandicam-2018-07-22-11-08-33-848.jpg (70.2 kB)
Show more comments
avatar image
1

Answer by hexagonius · Jul 22, 2018 at 11:11 AM

Just do a playerprefs for each level. Extend your key name with the level number. Use Set and GetInt to set 0 or 1 depending on the state of the level, not played or finished. This way, each LevelButton gets it's own state, initialized with 0 as not played yet.

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

Follow this Question

Answers Answers and Comments

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

cancle invokeReapeating not working 0 Answers

Player boundaries based on screen resolution 1 Answer

Help with Generating level 0 Answers

I want the player to move on to the next level once it has collected a coin. What would the script for that be? 0 Answers

Guides or Tutorials for a Very Basic Enemy AI? [Unity 5] 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