- Home /
List of bools assigned to each Gameobject in List/Array
So my goal here is to make a list of public GameObjects, then assign public bools to each of those Gameobjects which I can check and Uncheck in the inspector.
This is what it would look like in the inspector: Gameobject 0: Bool1 [] Bool 2 [] Bool 3[] GameObject1: Bool1[] Bool 2[] Bool 3[] GameObject3: Bool1[] Bool2[] Bool3[]
The []s represent checkboxes like you would see in the inspector with public bools.
This code is not ideal, as it's messy. Is there a way to do this without having to add another script to hundreds of objects?
for(int i = 0; i < Objs.Count; i++) {
boolList.Add(bool1);
BoolList.Add(bool2);
BoolList.Add(bool3);
BoolList.Add(bool4);
BoolList.Add(bool5);
}
Also is there a way to name them individually instead of Element0, Element1, Element2?
$$anonymous$$y idea: Write a custom class which holds the GameObject reference and the bools as. Then, use this class as the list's element typer ins$$anonymous$$d of GameObject.
Class example:
[System.Serializable]
public class $$anonymous$$yClass {
public GameObject go;
public List<bool> bools = new List<bool>();
}
And your list with usage example:
List<$$anonymous$$yClass> list = new List<$$anonymous$$yClass>();
listAd(new $$anonymous$$yClass());
list[0].go = someGameObject;
list[0].bools.Add(true);
list[0].bools.Add(false);
list[0].bools[1] = true;
Going to try this out soon, I ended up just making another script with the different Bools and auto adding them to the objects in the list. Thanks for your help!