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 SunPearl · Sep 03, 2013 at 11:37 AM · javascriptdatabasexmldata storagewindows phone

Collectables across multiple levels

I'm creating a project where the objective is to find objects in separate levels, however apart from having a GameObject that doesn't get destroyed I'm unsure where to go from here. I need a system that goes checks a database when loading a level and only creates the collectables that have not been found yet or destroys the collectables in the level that have already been found once the level is loaded.

alt text

Can anyone point me in the direction of a good place to start? The system needs to work on all of the mobile platforms (Windows Phone, iOS, Android, and Blackberry 10) and be possible in JS. I've read a bit about XML files however most tutorials are not built for those who are a newcomers of XML.

[Edit for Clarity] When I say database I meant a local file that stores the data for an object in the scene, basically in Unity I have 5 levels, in each level there are 3 collectables. When a level is loaded I want to have an array of GameObject called Collectables in a GameController object and use GameObject.FindGameObjectsWithTag("Collectable"); to populate that array. After that is done I want to read some sort of data file, the file needs to have an ID number for each level to only check the data that corresponds with the the id of the current level in Unity and an ID for each collectable, and then go through the data for each Collectable from the file, if a Collectable has the IsCollected value of true then it should destroy the GameObject from the Collectables array in the scene. I've done my best to write an XML that best portrays what I need in the data Here.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Sisso · Sep 03, 2013 at 12:54 PM

Give a unique name for each collectable, and put script like this:

 function Awake() {
     if (PlayerPrefs.GetString("collectables."+gameObject.name, "false") == "true") {
         GameObject.Destroy(gameObject);
     }
 }
 
 // it could be called directly or replaced by a trigger event
 function Collect() {
     PlayerPrefs.SetString("collectables."+gameObject.name, "true");
 }

After you call Collect, it will register on playerprefs and it will self destroy on awake.

Some usefull references:

PlayerPrefs

http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html

Colliders and triggers

http://docs.unity3d.com/Documentation/ScriptReference/Collider.html

Comment
Add comment · Show 6 · 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 SunPearl · Sep 03, 2013 at 02:18 PM 0
Share

Ouch, but I'll take that with a grain of salt, this is my first question on the site and may be taken for a complete newbie. I can program gameplay mechanics just fine and have completed half of my gameplay scripting (Fully working player, camera, enemies and cutscenes), I was looking for something more geared towards data handling, I've always been a gameplay programmer and this is my first venture into handling saving game data.

avatar image Sisso · Sep 03, 2013 at 02:53 PM 0
Share

Look, I really like to help if I can. But you be specific in one point.

What the relation of database? It is a local database? Remote database? All users share the same database? It is a client-server multiplayer? Need to be a database or could be any persistent storage? X$$anonymous$$L? What do you want with X$$anonymous$$L? Comunicate? Storage? What relation of X$$anonymous$$L and a mobile plataform? Edit the level using X$$anonymous$$L? Ouou... stack overflow :P

Or I could throw everything out and back to "how do you create a level where the already colletable objects don't appear?". It could be solved by one script, less that 10 lines of code and PlayerPrefs.

avatar image SunPearl · Sep 03, 2013 at 03:19 PM 0
Share

I think the last part of your comment sums it up nicely: How do I have collectables that don't appear if they have already been collected?

avatar image fafase · Sep 03, 2013 at 03:35 PM 0
Share

Look at UnitySerializer http://whydoidoit.com/unityserializer/

avatar image SunPearl · Sep 03, 2013 at 09:01 PM 0
Share

Thanks, I'll have a look at that and also the UnitySerializer page that fafase suggested, If I can limit the saving to just the objects tagged 'Collectable' then that seems like it would be the way to go :)

Show more comments
avatar image
0

Answer by ragnaros100 · Sep 03, 2013 at 02:23 PM

You can look at my series of questions I did some time ago:

http://answers.unity3d.com/questions/279650/create-text-file-in-c.html

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 fafase · Sep 03, 2013 at 02:24 PM 0
Share

This will save on the machine, not on a db. I think he wants a db connection. I could be wrong though.

avatar image ragnaros100 · Sep 03, 2013 at 02:24 PM 0
Share

oh well.. nvm then :)

avatar image
0

Answer by fafase · Sep 03, 2013 at 02:23 PM

Here is how to access and update db: http://wiki.unity3d.com/index.php?title=Server_Side_Highscores

Then you need to collect the info into a class and check what the player has done.

 if(level1 == Level.Done){//Allow access to level 1}
 if(level2 == Level.Done){//Allow access to level 2}

The rest is always the same, has he done it, if yes, allow something.

All you need is to get the script from the link working.

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.

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

Help on making a Database. 0 Answers

Scriptable Objects as a datatable 1 Answer

XmlException: unexpected end of file. Current depth 1 Answer

Dialogue strategy? 0 Answers

Where will those XML files be stored if the platform of this game is Web Player...? 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