Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!