Search Unity

Saving/Loading

Discussion in 'Scripting' started by Faestus, Nov 19, 2014.

  1. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
    Hello. Is there a good tutorial on how to save in Unity?

    I don't need a savegame, I need saved levels. If possible, also arraylists of multiple objects with different properties.
     
  2. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,422
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
  4. Faestus

    Faestus

    Joined:
    Jul 23, 2014
    Posts:
    68
    Thank yo
    u.

    How can I save something like this though?
    Code (CSharp):
    1. class PotatoFarm {
    2. ArrayList Plants = new ArrayList();
    3. void Grow() {
    4. for (var i=0; i<12;i++)
    5. {
    6. Potato This=new Potato();
    7. This.Potatoishness=i;
    8. this.Plants.Add(This);
    9. }
    10. }
    11. }
    12.  
    13. class Potato {
    14.   public float Potatoishness;
    15. }
    16.  
    I wanna save an arraylist of classes with different properties.

    Code (CSharp):
    1.  
    2. class ForumAvatar{
    3.  public Sprite[] Data;
    4. void LoadSprites() {
    5.  
    6. Data=  Resources.LoadAll<Sprite>("Avatar");
    7. }
    8. }
    9.  
    I want to save sprites. Is it possible somehow? So that players can load their own sprites into a game?
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    That video should answer your first question if you watch the whole way through.

    Sprites are a different story. You would probably have to use something like EncodeToPNG.