- Home /
using a static list between scenes
I am trying to use a class with a static list of Monsters between scenes, but I am having trouble passing it correctly. I've have looked for similar questions, but most seem centered on passing variable like integers, which is easier with PlayerPrefs.
What is the best way to create a List that I can use in other scripts and use between scenes?
Example of the monster class;
using UnityEngine;
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
public class PokemonList : MonoBehaviour {
public static List<Pokemon> pokemonList = new List<Pokemon>();
public static List<Pokemon> pokemonPcList = new List<Pokemon>();
private string regNumber1;
private string regNumber2;
void Awake()
{
DontDestroyOnLoad(this);
}
public void AddPokemon (string dictionaryName, int level, string regNumber) {
Pokemon caughtPokemon = PokemonDatabaseScript.pokemonDictionary[dictionaryName];
caughtPokemon.level = level;
caughtPokemon.regNumber = regNumber;
pokemonList.Add(caughtPokemon);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220611235531im_/https://answers.unity.com/themes/thub/images/avi.jpg)