FindGameObjectsWithTag returns null objects
Hello All!
I filled an array with given GameObjects (fruits) by declaring a public GameObject[] fruitArray, and dragging them from the scene to the script.
I am then picking random GameObjects from the array and instantiating them at the beginning of the script.
Below is the start method:
foreach (GameObject fruit in fruitArray)
{
Instantiate(fruitArray[Random.Range(0, fruitArray.Length)], new Vector3(Random.Range(-0.25f, 0.25f), Random.Range(1.4f, 0.7f), -9), transform.rotation);
}
In the Update(), I am searching for game objects with the tags to check if its not null; hence, to enable text and add the fruit to a list.
Now the problem is that eventhough a specific GameObject does not instantiate ( such as banana since its random instantiation), it is still being added in the fruit list array. So I am thinking that something is wrong with my method.
This is the update method:
if (GameObject.FindGameObjectsWithTag("Banana") != null) { fruitList.Add("Banana"); bananaTxt.enabled = true; }
Thanks!
Your answer
![](https://koobas.hobune.stream/wayback/20220612144527im_/https://answers.unity.com/themes/thub/images/avi.jpg)