So why can one use Blah = GameObject.FindWithTag("Blah").transform,
but you can't use Blah = GameObject.FindGameObjectsWithTag("Blah").transform?
What's the difference, and is there a simple workaround for finding the transforms of multiple objects with the same tag?
Thanks
system
2
GameObject[] blahObjects = GameObject.FindGameObjectsWithTag("Blah");
foreach(GameObject blah in blahObjects)
{
blah.transform ...
}
find objects returns an array not a single object to use.
You can use Array.ConvertAll()
GameObject[] Blahs = GameObject.FindGameObjectsWithTag("SomeTag");
Transform[] BlahTransforms = Array.ConvertAll<GameObject, Transform>(Blahs, x => x.transform );
Also LINQ (if you aren't targeting mobile):
var transforms = GameObject.FindGameObjectsWithTag("Blah").Select(g => g.transform);