Timer not working

So, I just put in a script named “platformScript.time” and the timer goes down in a matter of a second and the enemies don’t spawn in; here’s the script for it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class SpawnManager : MonoBehaviour
{
    public GameObject enemyPrefab;
    public GameObject newEnemyPrefab;
    public GameObject powerupPrefab;
    public GameObject hardPrefab;
    private int enemies;
   
    public TextMeshProUGUI waveText;



    public int enemyCount;
    public int waveNumber = 1;

    bool enemyStop;

    private PlatformScript platformScript;

    private int wave;
    private int spawnEnemies = 1;
   

    private float spawnRange = 9.0f;

    // Start is called before the first frame update
    void Start()
    {
        SpawnEnemyWave(waveNumber);

        Instantiate(powerupPrefab, GenerateRandomPosition(), powerupPrefab.transform.rotation);

        platformScript = GetComponent<PlatformScript>();
    }

    // Update is called once per frame
    void Update()
    {
        enemyCount = FindObjectsOfType<Enemy>().Length;
        if (enemyCount == 0 && platformScript.time == 0)
        {
            waveNumber++;
            WaveCounter(1);
            enemies = waveNumber;
            if (waveNumber > 3)
            {
                enemies = 3;
            }
            SpawnEnemyWave(enemies);
            Instantiate(powerupPrefab, GenerateRandomPosition(), powerupPrefab.transform.rotation);
            if (waveNumber >= 5)
            {
                SpawnNewEnemy(1);
            }
            if (waveNumber >= 10)
            {
                SpawnHardEnemy(1);
            }
           
        }

     


        if (waveNumber <= 6 && enemyCount >= 7)
        {
            Debug.Break();
            Debug.Log("Are you missing a variable in your code?");
        }
    }

    private Vector3 GenerateRandomPosition()
    {
        float spawnPosX = Random.Range(-spawnRange, spawnRange);
        float spawnPosY = Random.Range(-spawnRange, spawnRange);
        Vector3 randomPos = new Vector3(spawnPosX, 1, spawnPosY);

        return randomPos;
    }

    void SpawnEnemyWave(int enemiesToSpawn)
    {
        for (int i = 0; i < enemiesToSpawn; i++)
        {
            Instantiate(enemyPrefab, GenerateRandomPosition(), enemyPrefab.transform.rotation);
        }

    }

    void SpawnNewEnemy(int newToSpawn)
    {
        for (int i = 0; i < newToSpawn; i++)
        {
            Instantiate(newEnemyPrefab, GenerateRandomPosition(), newEnemyPrefab.transform.rotation);
        }

    }

    void SpawnHardEnemy(int hardToSpawn)
    {
        for (int i = 0; i < hardToSpawn; i++)
        {
            Instantiate(hardPrefab, GenerateRandomPosition(), hardPrefab.transform.rotation);
        }

    }

    public void WaveCounter(int newWave)
    {
        wave += newWave;
        waveText.text = "Wave: " + waveNumber;
    }

   

}

How do I fix this?

Equality comparison is your problem here. The time will basically never be equal to 0. It will go from something like 0.0034 to -0.0012 or whatever, never hitting 0.0 directly.

More info plus a list of solutions here

I tried to do the same with less than and the same thing happened, in the Unity window it says "
NullReferenceException: Object reference not set to an instance of an object
SpawnManager.Update () (at Assets/Scripts/SpawnManager.cs:47)"

That has nothing to do with your original problem.

How to fix a NullReferenceException error

https://forum.unity.com/threads/how-to-fix-a-nullreferenceexception-error.1230297/

Steps to success:

  • Identify what is null
  • Identify why it is null
  • Fix that

That’s not the “same thing”. Before, nothing was happening, and now, you’re getting an exception. (And I guarantee, this problem was there already, the code was just never getting executed until now.) Check Kurt’s link for this one.