Using Generic Lists and System.Linq works quite well.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class Example : MonoBehaviour
{
string[] tags;
List<GameObject> gameObjects = new List<GameObject>();
void Start()
{
tags = new string[]{"targetTag", "targetTag1"};
foreach(GameObject go in GameObject.FindObjectsOfType (typeof(GameObject)))
{
if(tags.Contains (go.tag))
gameObjects.Add (go);
}
print (gameObjects.Count);
}
}
And if I'll be calling this function every 10th second or so with 50+ enemies, will it cause loss of performance?
This works quite well - I know you wrote this as an example - but as an improvement, I would let the user fill in the tags array from the inspector instead of newing it up in Start.
And if I'll be calling this function every 10th second or so with 50+ enemies, will it cause loss of performance?
– frankyboy450Not if you're calling every 10 seconds. I just wouldn't call it in Update().
– clunk47Ok. Won't call it in the Update() ;) Thanks for the help ;)
– frankyboy450If this solution works out for you, don't forget to tick the answer / vote up ;) Happy Developing
– clunk47This works quite well - I know you wrote this as an example - but as an improvement, I would let the user fill in the
– vexetagsarray from the inspector instead of newing it up inStart.