I have an array that gets all the gameobjects with the enemyMelee tag and i want to put the ones that have the idEnemy equal to the idDestination in another array.
How can i do this?
The maybeBlobsEnemy is the array that has all of them and blobsEnemy is the array that i want with only the condition above
Here is my code
void Update()
{
maybeBlobsEnemy = GameObject.FindGameObjectsWithTag("blobMelee");
for (int i = 0; i < maybeBlobsEnemy.Length; i++)
{
if (maybeBlobsEnemy[i].GetComponent<BlobBehavior>().idBlob == idDestination)
{
blobsEnemy[i] = maybeBlobsEnemy[i];
}
}
Thank you for you time

using System.Linq; ... blobsEnemy = maybeBlobsEnemy.Where(item => item.GetComponent<BlobBehavior>().idBlob == idDestination).ToArray();- Panda StrongWhere, or simply use aList<GameObject>instead of an array, use your code and doblobsEnemy.Add(maybeBlobsEnemy[i]);instead ... in all cases: Do not do this inUpdate... it is very expensive - derHugo