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_); (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 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*);*_

_ PlayerPrefs.SetInt (“lista”,listItems*);*_

* }*

* } *

* // Update is called once per frame*
* void Update () {*

* }*
}

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

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

hmm
yes DistortedShadow :slight_smile:
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);