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 Smaika · Feb 14, 2015 at 07:08 PM · c#javascriptgameobjectsaveunique-identifiers

Don't Load Collected items

My Problem is that i have coins in the game (all coins are childs in one main EpmtyGameObject Prefab) and the player can collect them. but how can I make it NOT to load them again if the player has collected them,Using PlayerPrefs if possible because I want the user be able to restart the hole game (By clicking the reset game button on the settings of the game,Witch will reset PlayerPrefs) and have these coins back

(some levels have 2 coins some have more than 30)

Comment
Add comment · Show 1
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 hexagonius · Feb 15, 2015 at 03:34 PM 0
Share

If you know bit operations, you could save an integer to the playerprefs, where each bit represents the state of a coin (up to 31 bits if I'm correct). When instantiated or activated any other way, the parent could read that int, check each bit for 0 or 1 and activate or deactivate the corresponding coin.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Mmmpies · Feb 15, 2015 at 05:56 PM

Keep the coins referenced in an array of bools on the player. When you start a new game set all bools to false, when the player picks up a coin set that coins bool to true in the array.

When a level loads only show the coins set to false.

Don't know how many levels you have but you could have an array for each level.

You still need to save to playerprefs but, happily, that's been made a whole lot easier because of this:

ArrayPrefs2

Comment
Add comment · Show 5 · 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 Smaika · Feb 15, 2015 at 06:12 PM 0
Share

Sorry to ask, but how can I use it am totally new with ArrayPrefs2 (first time)

avatar image Mmmpies · Feb 15, 2015 at 06:21 PM 0
Share

Not used it myself yet, just knew it was there. Appears to be PlayerPrefsX.SetBoolArray but let me test some code so I'm not telling you bad info.

avatar image Smaika · Feb 15, 2015 at 06:45 PM 0
Share

thank you very much

avatar image Mmmpies · Feb 15, 2015 at 06:47 PM 0
Share

O$$anonymous$$ I'm familiar with C# so I'll show show a brief test I just carried out in C#:

 using UnityEngine;
 using System.Collections;
 
 public class testPPX : $$anonymous$$onoBehaviour {
 
     private bool[] levelOneCoins;
 
     void Start()
     {
         levelOneCoins = new bool[5] {true, true, true, true, true};
         TESTPPX();
     }
 
     void TESTPPX()
     {
         PlayerPrefsX.SetBoolArray("lvl1coins", levelOneCoins);
         Debug.Log (" levelOneCoins 0 = " + PlayerPrefsX.GetBoolArray("lvl1coins")[0]);
     }
 }

That just saves out to playerPrefsX the 5 values in levelOneCoins. I used the C# PlayerPrefsX from that web page.

Anyway the debug log just looks at the 0 element in that saved array. You can also do:

 Debug.Log(PlayerPrefsX.GetBoolArray("lvl1coins").Length);

Which, in this case, is 5.

EDIT

Hmmm, should really show you how to get the values as well:

 private bool[] gotLevelOne; // add this at the top
 
 
 //and add this to the TESTPPX
 gotLevelOne = PlayerPrefsX.GetBoolArray("lvl1coins");
         Debug.Log("BOOL " +gotLevelOne[0] + "  length = " + gotLevelOne.Length);
avatar image Mmmpies · Feb 15, 2015 at 06:59 PM 0
Share

No problem, if it answered your question you should really tick it as correct. It helps all round, I get a few $$anonymous$$arma points, you don't get a reputation for not ticking. Stops others from trying to answer it and helps people with similar issues.

Get a rep for not ticking and a lot of people will ignore your questions.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

when mouse is on a object do this 2 Answers

press e to speek -1 Answers

Distribute terrain in zones 3 Answers

Save Players Creation to be opened later 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