I have a button in my scene that works as a toggle for all the objects that are included on its list. I also have some objects that i would like to instantiate and attach them to the list of the toggle button. Any ideas how do i do that? In other words i wanna do this but with with objects that are instantiated.
Heavy PseudoCode incomming untested but should give an idea:
[SerializeField] Toggler _toggler;
void Awake()
{
_toggler = GetComponent<Toggler>();
}
void MyFunction()
{
var myObj = Instantiate(MyGameObject, MyParentObject);
_toggler.toggles.add(myObj);
}
you need to find all the objects you want to add to that toggles list/array, if its a list you could do something like this using a tag
List<GameObject> Toggle= new List<GameObject>();
Toggle.AddRange(GameObject.FindGameObjectsWithTag("TagOfYourObjects"));
you can find your objects any other way this is just an example.