Enemy Problem Help?

I made a script that duplicates an enemy that I have in my scene so that there are a lot of them instead of just one. However, when I destroy the original enemy, the duplication script no longer works because the gameobject is missing. How would I work around this?

here is the duplication script, by the way:

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

public class SpawnEnemy : MonoBehaviour
{
    public GameObject enemytospawn;
    public Transform spawnplace;

    IEnumerator task()
    {
        Instantiate(enemytospawn, spawnplace.position, spawnplace.rotation);
        yield return new WaitForSeconds(5.0f);
        StartCoroutine(task());
    }

    void Awake ()
    {
        StartCoroutine(task());
    }
}

of course if you destroy the original enemy which is “enemytospawn”… it will become null therefore your instantiate script will not work… destroy the instances you make not the original…

I understand why its happening, but how do I make the first enemy not chase me? I shouldn’t be able to kill it at all.

Put the your enemy in project inside a folder as a prefab (it will become a blue box inside project)…
then drag drop it in the spawn script inside the scene (the spawn script should have its own gameobject)… so now your script only create clones from the prefab, and the prefab reside inside your project unharmed… :slight_smile:

This works, but the clones of the enemy cannot hit me or deal damage. I don’t know how to fix this.