Question by
Daniel_Abeleira · Nov 14, 2018 at 04:52 PM ·
c#findgameobjectswithtag
How to find all GameObjects with different tags excluding some tags.
For my game, I need to show all the objects on the level the player is in and hide all the others. This means I need to show all objects with tag ("lvl" ´+ (player.level - 1)) and hide objects with greater or smaller tags. My code now looks like this.
objectsToShow = GameObject.FindGameObjectsWithTag("lvl" + pj.level.ToString());
for (int i = 0; i < objectsToShow.Length; i++)
{
objectsToShow[i].SetActive(true);
}
//Hide objects
if (pj.level != 1)
{
objectsToHide = GameObject.FindGameObjectsWithTag("lvl" + (pj.level - 1).ToString());
for (int i = 0; i < objectsToHide.Length; i++)
{
objectsToHide[i].SetActive(false);
}
Comment
Your answer
Follow this Question
Related Questions
FindGameObjectsWithTag and then find a variable C# 1 Answer
I can't find child objects with using FindObjecstswtihTag, need help. 0 Answers
Compare GameObject with an array 1 Answer
Check if 2 or more objects of same type is near object. 1 Answer
Referencing variable from another script on another object 3 Answers