Find Many GameObjects by name

Hello!I want to find many GameObjects with name “something+LOD1”.How i can do it?GameObject.Find return only one GameObject but i need many!!Thanks

2 Answers

2

foreach(GameObject gameObj in GameObject.FindObjectsOfType())
{
if(gameObj.name == “something+LOD1”)
{
//Do what you want…
}
}

Thanks, but I don't need to search "something".I mean,how I can write code that unity will find all game objects which name contains "lod1" and some other words?

if(gameObj.name.Contains("+LOD")) // ... add to a list or do something with it right away That's all it takes. This answer is basically right, just the .Contains portion refines it to what you just asked.

Give them a common tag, and use GameObject.FindGameObjectsWithTag(objectsTag); I hope you know how to create tags.