Tried to add a new enemy prefab and now my whole spawn system is broken

Okay, so I had a spawn gameobj that would spawn an enemy at certain points in the map, and the enemy had a script that would delete the enemy within a few seconds. this worked well before, with the enemy spawning at a random specified point, deleting, then respawning again. I tried to add another enemy prefab to my project along with a copy-pasted spawn gameobj and somehow it broke everything. Now when I start the game, the enemy spawns outside the map, and never spawns again once deleted. Even when I completely remove the new enemy and spawn points, its still broken. Here is the spawner code:


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class SpawnCode : MonoBehaviour
{
    public GameObject normalEnemyPrefab;
 
    public GameObject[] SpawnPoints;
 
    Vector2 whereToSpawn;
 
    public float spawnRate = 4;
 
    float nextSpawn = 0.0f;
    
     
    void Start()
    {
        
    }

    
 
    void Update()
    {
        CallLater.DoAfter(120, x =>
        {
            if (Time.time > nextSpawn)
            {
                nextSpawn = Time.time + spawnRate;

                var spawnPointGameObject = SpawnPoints[UnityEngine.Random.Range(0, SpawnPoints.Length)];
                var whereToSpawn = spawnPointGameObject.transform.position;
                var spawnRotation = spawnPointGameObject.transform.rotation; //will face and move the same rotation as the spawn point


                Instantiate(normalEnemyPrefab, whereToSpawn, spawnRotation);

            }
        });
    }


      


}

Please help! My game is unplayable in this state…Thank you for reading

You haven't shared the code for EnemySpawner, so it's hard to help. You need to fix the UnassignedReferenceException first. Also you Update() would spawn an enemy every update. Which means you would end up with 7,000 enemies.

–

I just realized that error is for a different spawner that I never used, it took me a few tries to make a working spawn script and I never deleted that one. My original issue is still there. Also, the spawnrate controls the amount of enemies

–

1 Answer

1

Im dumb, see that 120? Thats 120 seconds when I meant to put 12. The thing wasnt happening in time and I freaked out. My bad!