- Home /
Question by
MSachs · Sep 05, 2018 at 09:14 AM ·
scripting problemgetcomponentrenderer
Get the renderer of multiple GameObjects at the same time?
Hi,
if I find GameObjects by tag using the following code at least one of them will have their Renderer disabled. How would I go ahead and get the Renderer of all of the GameObjects to enable them again?
GameObject[] go = GameObject.FindGameObjectsWithTag("ABC");
If I would go ahead to activate/deactivate all of them using this technique it works with this:
for (int i = 0; i < go.Length; i++)
go[i].SetActive(true);
Is there a similar way to do this with activating/deactivating certain components like the Renderer?
Thanks in advance :)
Comment
Best Answer
Answer by LeeJBaxter · Sep 05, 2018 at 09:56 AM
This should work...
public void EnableGameObjectRenderers(string tag)
{
foreach (GameObject go in GameObject.FindGameObjectsWithTag("ABC"))
{
Renderer renderer = go.GetComponent<Renderer>();
if (renderer != null)
{
renderer.enabled = true;
}
}
}