Enemy spawner troubles

I’ve created a Spawner prefab and the code. I’m not sure why, but it’s not spawning any enemies. I’m sure it’s a simple mistake that I’m overlooking, so maybe a second set of eyes will help me. No errors are being thrown in the console

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;

public class SpawnerScript : MonoBehaviour
{
    public GameObject enemyPrefab;
    public GameObject[] spawnPoints;
    private float timer;
    private int spawnIndex = 0;
    private float health = 5;
    public Sprite deathSprite;
    public Sprite gateway;
    private bool isGateway = false;

    public Sprite weaponUpgrade;
    private bool isWeaponUpgrade = false;

    public Sprite[] sprites;

    private GameManager gameManager;

    void Start()
    {
        gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
        Instantiate(enemyPrefab, spawnPoints[0].transform.position, Quaternion.identity);
        Instantiate(enemyPrefab, spawnPoints[1].transform.position, Quaternion.identity);
        timer = Time.time + 7.0f;
        int rnd = Random.Range(0, sprites.Length);
        GetComponent<SpriteRenderer>().sprite = sprites[rnd];
        gameManager.SetZombieCount(2);
    }

    void Update()
    {
        if(timer<Time.time && gameManager.GetZombieCount()< gameManager.GetZombieLimit())
        {
            if (GetComponent<SpriteRenderer>().sprite != gateway)
            {
                Instantiate(enemyPrefab, spawnPoints[spawnIndex % 2].transform.position, Quaternion.identity);
                timer = Time.time + 7.0f;
                spawnIndex++;
                gameManager.SetZombieCount(1);
            }
        }
    }

    public void TakeDamage(float amount)
    {
        if (GetComponent<SpriteRenderer>().sprite != gateway)
        {
            health -= amount;
            GetComponent<SpriteRenderer>().color = Color.red;
            if (health < 0)
            {
                GetComponent<SpriteRenderer>().sprite = deathSprite;
                if (isGateway)
                {
                    Invoke("OpenGateway", 0.5f);
                }
                else if (isWeaponUpgrade)
                {
                    Invoke("OpenWeapon", 0.5f);
                } else
                {
                    Invoke("DestroySpawner", 0.6f);
                }

            }
            Invoke("DefaultColor", 0.3f);
        }
    }

    private void OpenGateway()
    {
        GetComponent<SpriteRenderer>().sprite = gateway;
    }

    private void DestroySpawner()
    {
        Destroy(gameObject);
    }

    private void DefaultColor()
    {
        GetComponent<SpriteRenderer>().color = Color.white;
    }

    public void SetHealth(int newHealth)
    {
        health = newHealth;
    }

    public void SetGateway(bool maybe)
    {
        isGateway = maybe;
    }

    public void GetGatewayWeapon()
    {
        if(GetComponent<SpriteRenderer>().sprite == gateway)
        {
            gameManager.LoadLevel();
        } else if (GetComponent<SpriteRenderer>().sprite == weaponUpgrade)
        {
            GameObject.Find("Weapon").GetComponent<WeaponScript>().UpgradeWeapon();
            Destroy(gameObject);
        }
    }

    public void SetWeapon(bool maybe)
    {
        isWeaponUpgrade = true;
    }

    private void OpenWeapon()
    {
        GetComponent<SpriteRenderer>().sprite = weaponUpgrade;
    }
}

What debugging have you done so far?

Have you checked that the code you expect to run is even running then?

Start with the code you expect to run, and if it isn’t running, work backwards from there.

Place some Debug.Log messages throughout the code to find out which methods are not being called.

That’s a lot of code… is any of it even running? Find out before you start agonizing about the code being correct or not.

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Those if-branches are a typical candidate for refactor. The O in SOLID, open/closed principal.

Types are open for extension but closed for modification.

While we’re nagging… there must be a permanent link to “don’t do this” when the exact same component is fetched over and over and over :upside_down_face: