- Home /
Assigning instantiated objects to a List of a Toggle button
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.
Answer by xxmariofer · Feb 20, 2019 at 12:02 PM
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.
Answer by SteenPetersen · Feb 20, 2019 at 11:59 AM
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);
}
Your answer
Follow this Question
Related Questions
While Loop Not Assigning Array 1 Answer
assigning gameobject to instantiated gameobjects script 2 Answers
Assign Names Problem 1 Answer
How to clone a material in each instantiated prefab as Unique temporary material. 6 Answers
Instantiate multiple objects that follow the FirstPersonController 1 Answer