- Home /
Question by
raghu220805_unity · Apr 15, 2020 at 01:20 AM ·
c#taggameobjectsdisableenable
How do I enable and disable multiple game objects in Unity?
I Need to Enable and Disable Multiple Gameobjects that contain Same Tag in Unity. C#,I need to enable and disable multiple game objects that contain same tag
Comment
Answer by Arshww · Apr 15, 2020 at 01:44 AM
This is the way i'd do it, it's not a "good performance" way but should work.
private GameObject[] objs;
void Start()
{
objs = FindObjectsOfType(GameObject); // this will look for all gameobjects and add them in the objs array
}
//Use this to disable all gameobjects with your tag
public void DisableGO()
{
foreach(GameObject obj in objs)
{
if(obj.CompareTag("YOUR TAG HERE"))
{
obj.SetActive(false);
}
}
}
//use this to enable all gameobjects with your tag
public void EnableGO()
{
foreach(GameObject obj in objs)
{
if(obj.CompareTag("YOUR TAG HERE"))
{
obj.SetActive(true);
}
}
}
Your answer
Follow this Question
Related Questions
Turn off multiple lights 0 Answers
Multiple Cars not working 1 Answer
I need to find a Script and Disable/enable it.. 1 Answer
using Aim Constraint 1 Answer
How do I disable The MouseLook script when "I" is pressed. 3 Answers