Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

366
Visualizações
Get list from another script in unity

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>();
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda