Hello! So, I am trying to create an spawner for the monsters to spawn at. The game starts with a slime and a goblin on the field, and I want more of those to spawn in over time. However, when I use the script I have right now, my slime becomes super fast and just bounces around everywhere. Then, when I kill that slime, the next slime spawns in (but without the healthbar until I hit it). But THEN, when another slime tries to spawn in, the previously spawned slime begins moving super fast and the new slime doesn’t spawn. Any ideas? Here is the respawn code:
using UnityEngine;
public class GooberSpawner : MonoBehaviour
{
public GameObject gooberPrefab; // Prefab for the Goober enemy
public Transform spawnPoint; // Spawn point for the enemies
// Spawn interval in seconds
public float spawnInterval = 5f;
// Start is called before the first frame update
void Start()
{
// Start spawning Goobers
InvokeRepeating(“SpawnGoober”, 0f, spawnInterval);
}
// Method to spawn a Goober at the spawn point
void SpawnGoober()
{
// Check if the spawn point and Goober prefab are assigned
if (spawnPoint != null && gooberPrefab != null)
{
// Instantiate a Goober at the spawn point position with default rotation
GameObject goober = Instantiate(gooberPrefab, spawnPoint.position, Quaternion.identity);
goober.SetActive(true); // Ensure Goober is active
}
else
{
Debug.LogWarning(“Spawn point or Goober prefab is not assigned in the inspector.”);
}
}
}