Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to save a coin dozer state in unity?

Discussion in 'Editor & General Support' started by mineschan, Jul 11, 2014.

  1. mineschan

    mineschan

    Joined:
    Jul 11, 2014
    Posts:
    3
    Hi everyone! I'm a freshman on 3d game development.
    I've read some tutorials myself and I know how to save some value to PlayerPrefs already.
    But as I am making a coin pusher game, dropped coin should remain the same if player quit and come back again.

    What techni should i use for this purpose?
    Like let say... can I save hundreds of dropped coins's transform to an array and load it later?

    Thanks everyone and who can give me some advise.=)
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    Yes that's pretty much exactly what to do. You could tag every coin/object then iterate through them all, saving type and transform to a couple arrays, then save the data somehow - which can be tricky. Look into serialization and some save/load examples to figure out what fits your project best. Good luck!
     
  3. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    Gonna be a tough one, not only do you need to save them all but when you load them you will have to Instantiate in a certain order so that coins above other coins dont drop before the lower coins are instantiated.
     
  4. mineschan

    mineschan

    Joined:
    Jul 11, 2014
    Posts:
    3
    Can you provide more keyword for me to search, serialization i got something like stream.serialize() but i can't figure it out what is stream yet. Thanks mate ><
     
  5. mineschan

    mineschan

    Joined:
    Jul 11, 2014
    Posts:
    3
    you're rite....never think about this

    for this issue maybe i should disable their reaction to gravity first, and reenable after all coins are instantiated? Do you think it will works?
     
  6. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    could work. prolly easier to shut off all gravity rather then do it for every coin then
     
  7. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    If you make rigidbodies kinematic until they are all ready they won't drop on top of each other, just instantiate a prefab which has the rigidbody kinematic set true, and then when they have all finished loading, turn off kinematic. For serialization I can't help a whole lot since I haven't tried it on any of my projects, but there are some assets (some paid) which can help you get a head start there, like I think posted on the asset store there are a couple pretty good looking save load systems with serialization. Also WhyDoIDoIt also posted a free alternative you could look into how that works:

    http://forum.unity3d.com/threads/unity-save-game-level-serialization.138678/

    And if you don't care to learn how that all works, you could do regular playerprefs style save load (which sometimes is enough for more simple games) where you just take data thats important (transforms and type of object) and save to playerprefs on any device. You could try something like this to improve performance of save/load times for playerprefs:

    http://www.previewlabs.com/writing-playerprefs-fast/

    Good luck!
     
  8. Kilrath81

    Kilrath81

    Joined:
    Nov 19, 2013
    Posts:
    153
    Keep in mind the Player Prefs are plain text and editable.