# How to respawn enemies after one is destroyed?

So I am doing this simple arcade style shooter game. My problem is that I know once my laser hits the enemy object it should get destroyed but once it get destroyed it is gone forever. I want to know how can I have a continuous enemy objects come at my spaceship even if it is destroyed. Its a 2d game but when I set up my game I followed the official unity3d beginner space shooter tutorial. In that tutorial coroutine were used but I am doing mine a bit differently. Here is how my code looks

``````using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour {

Transform myTransform;
public int minSpeed;
public int maxSpeed;
int x,y,z;
public int currentSpeed;

// Use this for initialization
void Start () {
x = -7;
y =  0;
z = 14;
myTransform = transform;
myTransform.position = new Vector3(x,y,z);
currentSpeed = Random.Range(minSpeed,maxSpeed);
}

// Update is called once per frame
void Update ()
{
x= Random.Range(-12,12);

myTransform.Translate(Vector3.back * currentSpeed * Time.deltaTime);
//everytime the enemy object goes beyond z=-6 it dissapears and creates a new enemy object
if(myTransform.position.z < -6)
{
myTransform.position = new Vector3(x,y,z);
currentSpeed = Random.Range(minSpeed,maxSpeed);
}
}
void OnTriggerEnter(Collider collider)
{
if(collider.gameObject.CompareTag("Projectile"))
{
Destroy(this.gameObject);
}
}

}
``````

Now, there wasn’t too much info that you provided us with for us to give a solid answer, but I’d say use the Instantiate method. Here’s an example of it in use:

``````void OnTriggerEnter (Collider collider) {

if(collider.gameObject.CompareTag ("Projectile")){
//Right now, all you have is this
Destroy(this.gameObject);
//If you add this, it should instantiate a new enemy prefab
Instantiate(EnemyPrefab, EnemyPrefabPosition, Quaternion.identity);
//the quaternion is just to show that there's now rotation
//I used placeholder names as well.
//Check the scripting reference for Instantiate for more info.
}
``````

}