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 Darioszka · Feb 05, 2015 at 06:24 PM · listsaveload

save load list

Hello I'm still learning and this is first time that I must save and load list.

I'm doing this: PlayerPrefs.SetInt ("lista",listItems[i]); (bottom of script)

I don't know how can I load this list in another scene.

this is script where I save list

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic; 
 
 
 public class wyborPrzedmiotow : MonoBehaviour {
 
     public GameObject[] items;
     public int itemCounter = 0;
     private int curIndex;
     public int maxImages;
     public string xName = "items";
     public bool a;
     public bool a2 = false;
     public GameObject Grid;
     public List<int> listItems;
     
 
     // Use this for initialization
     void Start () {
 
         List<int> listItems = new List<int>(new int[] {});
 
                 // You can add additional tests also I would enclose the instantiation inside a method then that would probably be useful as you could then call it from other places
                 maxImages = 5;
     
 
 
 
 
         for (int i = 0; i < maxImages; i++) {
 
         
                     
                         if (items.Length != 0 && items [curIndex] != null) {
             
 
 
                 curIndex = Random.Range (0, items.Length);
 
                 
 
 
 
                                 
                 xName = "items" + curIndex;
 
                         foreach (Transform child in transform) {
             
 
                         if (child.name == xName) {
         
                         a = true;
                         //print ("true");
                 
                                         }
 
 
                 }
 
                 while (a == true)
                          {
 
                         curIndex = Random.Range (0, items.Length);
                         
                         
                         
                         
                         //elementsToExclude.Add (curIndex);
                         
                         xName = "items" + curIndex;
                     a = false;
 
                         foreach (Transform child2 in transform) {
                             
                             
                             
                         if (child2.name == xName) {
                             
                             a = true;
                         //    print ("true");
                                 
                             }
 
 
 
                     }
 
                             
                 
                 }
                 
 
 
                 if ( a == false)
                 {
                 GameObject currentItem = (GameObject)Instantiate (items [curIndex], Vector3.zero, Quaternion.identity);
                 currentItem.transform.parent = Grid.transform;
                 currentItem.name = string.Format ("items" + curIndex);
                 listItems.Add (curIndex);
                 //itemCounter++;
             
                 
                 
                 }
                 
 
 
             }
 
             Debug.Log(listItems[i]);
         
 
             PlayerPrefs.SetInt ("lista",listItems[i]);
         
         }
 
 
     }    
 
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 

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

Answer by VesuvianPrime · Feb 05, 2015 at 06:26 PM

There is an excellent library here that provides functionality for storing collections in prefs.

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
avatar image
0

Answer by KazooCar69 · Feb 05, 2015 at 06:27 PM

The way I pass data between scenes is by using DontDestroyOnLoad(), but you're probably looking for something more elegant.

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
avatar image
0

Answer by Darioszka · Feb 05, 2015 at 07:11 PM

hmm yes DistortedShadow :) but I think I do this with something like this from link to library of VesuvianPrime

 var numberArray = new int[10];
 for (n in numberArray) n = Random.Range(-10, 11);
 PlayerPrefsX.SetIntArray ("Numbers", numberArray);
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

List Contains false after playmode 0 Answers

How to save a progress by user with diferent users 2 Answers

Save and Load Function 2 Answers

How i can PlayerPrefs List<>? 0 Answers

How to save and load `List myList`? 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