I would like to get a value from a serialized list that is on another script. How can I do that? This is my list:
[System.Serializable]
public class Level
{
public string Name;
public Sprite Icon;
public bool Unlocked;
public bool Interactable;
}
public List<Level> levelList = new List<Level>();
First you need to put your list inside the scope of the class like this:
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Level {
public List<Level> levelList = new List<Level>(); //List inside the class
public string Name;
public Sprite Icon;
public bool Unlocked;
public bool Interactable;
}
On your accesor class you need to have a class variable so that you can access that level instance. Then somewhere get the list of that level instance, as in for exmaple in the Start of the code below.
using System.Collections.Generic;
using UnityEngine;
public class ListGetter : MonoBehaviour
{
public Level level;
private List<Level> levelList;
void Start()
{
levelList = level.levelList; //get level list
}
}
You would need to define how your Level instance is created, and the class that holds the instance of the class to provide a more accurate way of accessing the levelList of your Level instance, which I think is what you are asking