- Home /
using classes in List<>'s
I have this code in my primary script (inspector script)
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class employee_List_Script : MonoBehaviour {
[Tooltip("employee List")]
public List<employee_List> emp_list = new List<employee_List>();
}
and my script the list's
using UnityEngine;
using System.Collections;
[System.Serializable]
public class CurrentEmployee_List
{
public class SomeRandomName
{
string name;
int shoot;
int creativty;
int work;
float maxEnergy;
float salary;
}
}
But the "SomeRandomName" class isn't showing in the inspector, any idea how could solve this?
Comment
Answer by RudyTheDev · Dec 19, 2014 at 10:42 PM
First, it needs to be serializable, second you need an actual variable/instance, like you have with public List
. And the fields all need to be public
(or marked as [ SerializeField ]
).
[System.Serializable]
public class CurrentEmployee_List
{
[System.Serializable]
public class SomeRandomName
{
public string name;
public int shoot;
public int creativty;
public int work;
public float maxEnergy;
public float salary;
}
public SomeRandomName actualClassInstanceVariable;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613174443im_/https://answers.unity.com/themes/thub/images/avi.jpg)