CS1061 error for 'GameObject'[] does not contain a definition for 'transform'

Getting this code, tried to find a solution on many other forums and tried to rewrite the code and check every spelling error, and nothing could be found…
Severity Code Description Project File Line Suppression State
Error CS1061 ‘GameObject[ ]’ does not contain a definition for ‘transform’ and no accessible extension method ‘transform’ accepting a first argument of type ‘GameObject[ ]’ could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\Mat\Game_1_01\Assets\Scripts\WaveSpawner.cs 33 Active
It’s showing me an error by highlighting .transform on line 20.
Thanks in advance for your help.

public class WaveSpawner : MonoBehaviour
{
    [System.Serializable]
    public class Wave
    {     
        public Enemy[] ennemies;
        public int count;
        public float timeBetweenSpawns;
    }
    public Wave[] waves;
    public Transform[] spawnPoints;
    public float timeBetweenWaves;
    private Wave currentWave;
    private int currentWaveindex;
    private Transform player;

    private void Start()
    {
        player = GameObject.FindGameObjectsWithTag("Player").transform;
            StartCoroutine(StartNextWave(currentWaveindex));
    }

    IEnumerator StartNextWave(int index)
    {
    yield return new WaitForSeconds(timeBetweenWaves);
        StartCoroutine(SpawnWave(index));
    }

    IEnumerator SpawnWave (int index)
    {
        currentWave = waves[index];

        for (int i = 0; i < currentWave.count; i++)
        {
            if (player == null)
            {
                yield break;
            }
            Enemy randomEnemy = currentWave.ennemies[Random.Range(0, currentWave.ennemies.Length)];
            Transform randomSpot = spawnPoints[Random.Range (0, spawnPoints.Length)];
            Instantiate(randomEnemy, randomSpot.position, randomSpot.rotation);

            yield return new WaitForSeconds(currentWave.timeBetweenSpawns);
        }
    }
}

There are two different methods.
FindGameObjectsWithTag
and
FindGameObjectWithTag
the second which doesn’t have a documentation page, but returns a drastically different result.

2 Likes

Thanks alot Panda, didnt notice this even after multiple reads. New to coding and didnt even knew there was ObjectsWithTag, just the autofill that lead me to this.

there is FindWithTag
FindGameObjectWithTag was probably made obsolete, probably because the slight difference in its name causes confusion.

1 Like