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 Tekksin · Apr 12, 2014 at 06:25 PM · playerprefssavelevelcollectionsachievements

Accomplishments in each Level not Saving

Say you make a game where in each level there are 3 things to do, aside from finishing the level. for example: One is to finish the level without being hit, the other to collect an item, and the last to finish the level in a certain amount of time.

You get badges for these accomplishments, and see them displayed at the end of that particular level. The next level offers the same tasks (minor tweaks in the editor and inspector. That part is already set up).

How does one complete the 3 tasks on level 1, and only see what was completed on that level, and then progress to the second level where he or she only sees what was accomplished in the second level? It is essential that player be able to leave level one, and return to see what has and hasn't been accomplished. Currently, they are not saved.

My researched has pointed fingers at XML, arrayPrefs2, GetInstanceID, DontDestroyOnLoad, and many other things. All of which I'm not particularly sure of how to tackle for my intentions, but could very well be the key to getting it done. How would you?

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

Answer by KittyKatKat · Apr 12, 2014 at 06:35 PM

I'd probably save it in a specific PlayerPref file by doing something like (this is just an example to give you an idea):

 PlayerPrefs.SetFloat("Level " + Application.loadedLevel.ToString(), pointsAcquired);

Then, when you want to load those points, just do:

 PlayerPrefs.GetFloat("Level //That level number//");

You might do some extra research about player prefs on the wiki. (I'm really no expert my self!)

On the other hand, one thing worth noting is that PlayerPrefs is not really a 'secure' code. It's easily editable by the player if he knows what he's doing. But if that's just a single player game with no online-score-sharing thing, players are only going to ruin their own fun by doing so.

I hope I at least somewhat helped :)

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 Tekksin · Apr 12, 2014 at 06:52 PM 0
Share

Thanks for the response! Couple questions:

I have a variable set up to tell the script which level I am on (cleverly titled: "thisLevel"). When you write '"Level " + ', are you referring to the level the player is on? And can I subsequently replace that with my "thisLevel" variable?

(or is "application.loadedlevel" essentially my "thisLevel" variable?)

does anything go in the parenthesis of "loadedlevel.ToString()"?

and pointsAcquired is I know just your example of what to have the script save in, but my $$anonymous$$i tasks are set up with booleans. Either they have them or they don't. How would you go about setting that up? $$anonymous$$eep in $$anonymous$$d, if the player gets 2 accomplishments, it could be the first and second, the second and third, or the first and third. So a numerical set up wouldn't work.

thanks again!

avatar image KittyKatKat · Apr 12, 2014 at 07:06 PM 0
Share

It takes out the index of the level when you preform the command Application.loadedLevel (to find out what the indexes are, go to File -> Build Settings... And on the right side below 'Scenes in build'. ToString simply puts that number as an ASCII/string. You can make a variable which could contain the level you're playing simply by doing (I'm using C#, I don't know how much that suits you, but I think JS is similar)

 private int thisLevel = Application.loadedLevel;

pointsAcquired is just some variable I made up that contains a float (I'm assu$$anonymous$$g you're points are a variable of the 'float' type. You can store integers as well with SetInt and so on. Also you don't have to put anything as a parameter of the ToString() command, it converts the number 'behind' it automatically.

I just tried setting a player pref for a boolean to test it out, but couldn't find it. You could however convert a boolean into an intiger, like:

 if (someBool)
     PlayerPrefs.SetInt("someInt", 1);
 else
     PlayerPrefs.SetInt("someInt", 0);

And take that integer later and perhaps turn it back into a bool. Like (this all just comes out of my head):

 if(PlayerPrefs.GetInt("someInt"))
     someBool = true;
 else
     someBool = false;

(the reason why I didn't have to do PlayerPrefs.GetInt("someInt") == 1 is simply because, C (I'm not sure about C#, you might have to test that out, but I'm very sure it's the same) language takes every value other than 0 as true. so it will automatically take 1 as true and 0 as false.)

As for multiple booleans, you could just raize the potential value of the integer (someInt could be any whole number - 0, 1, 100, 3141 etc.)

I hope it at least somewhat makes it more clear.

avatar image Tekksin · Apr 14, 2014 at 10:18 AM 0
Share

it worked!! You are amazing!! THAN$$anonymous$$ YOU SO $$anonymous$$UCH!!! It took some finagling, but the basis of what you shared here saved me thousands of lines of code!

avatar image KittyKatKat · Apr 16, 2014 at 05:18 PM 0
Share

I'm glad it worked out! ^^

avatar image
0

Answer by nicolasjr · Apr 12, 2014 at 06:37 PM

Well, I think that you should take a look on the arrayPrefs2. That's, in my opinion, the best way to handle your demand. You have no alternative, it seems, if not keep the badges accomplishments recorded, so, I'd definitively go with that approach.

Comment
Add comment · Show 1 · 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 Tekksin · Apr 12, 2014 at 07:01 PM 0
Share

is there any info you can give me to nudge me in the right direction? I looked at the wiki but it's filled with such broad info, I find it hard to know what to try.

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

23 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

Related Questions

Set int to object from list? 0 Answers

Saving character selection 1 Answer

PlayerPrefs for FPS? 1 Answer

Enemy saving multiple defeats 1 Answer

Level exporting (with video example) 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