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 () {*
* }*
}