Question by
techadvancing · Feb 03, 2018 at 11:09 AM ·
gameobjecttagdisplayfindgameobjectswithtagrenderer.enabled
Turn on/off renderer for objects found with "FindGameObjectsWithTag"
Hello, I'm trying to display a level of a game by enabling the mesh renderer for all the objects in the level once the player reaches a certain checkpoint and collides with it, but I can't seem to make the code work:
if (collision.collider.name == "checkpoint1")
{
GameObject.FindGameObjectsWithTag("level2").renderer.enabled = true;
}
The problem is .renderer property cannot be used with the GameObjects finder. Does anybody know a way to solve this or an alternative? Thanks.
Comment
Any help please? :C I still haven't figured it out. $$anonymous$$uch appreciated if somebody could offer a hint!
Best Answer
Answer by ArchLevelChris · Feb 03, 2018 at 03:37 PM
the problem is "FindGameObjectsWithTag" get a array of GameObjects back u can use this
if (collision.collider.name == "checkpoint1")
{
GameObject[] objects = GameObject.FindGameObjectsWithTag("level12");
foreach(GameObject obj in objects)
{
obj.GetComponent<Renderer>().enabled = true;
}
}
Thank you! Your code works and has fixed the problem!