Unity2D: How do I stop instantiate spawn (clone)?

Hi, so basically I have a game over panel, with an animation attach to it to make the panel slide down when the player loses all of his lives. I created a UI script to help me pause and unpause game objects behind the The game over panel when it comes down. It works but I have enemies that spawns randomly in my game, so the clones aren’t being paused when the gamover panel comes down. Does anybody know how to stop cloning object when the game over panel is paused.
This is my spawning script: (Javascript)

   #pragma strict

      // Variable to store the enemy prefab
         public var enemy : GameObject;
         public var gameCharacters : GameObject;

      // Variable to know how fast we should create new enemies
         public var spawnTime : float = 2;

              function Start() {  
                // Call the 'addEnemy' function every 'spawnTime' seconds
                   InvokeRepeating("addEnemy", spawnTime, spawnTime);
                   }

      // New function to spawn an enemy
             function addEnemy() {  
      // Variables to store the X position of the spawn object
      // See image below
             var x1 = transform.position.x - GetComponent.<Renderer>().bounds.size.x/2;
             var x2 = transform.position.x + GetComponent.<Renderer>().bounds.size.x/2;

         // Randomly pick a point within the spawn object
             var spawnPoint = new Vector2(Random.Range(x1, x2), transform.position.y);

         // Create an enemy at the 'spawnPoint' position
              Instantiate(enemy, spawnPoint, Quaternion.identity);
               }

And this is how I pause my game (within my UI script):

  public class UIManagerScript : MonoBehaviour {

public GameObject gameCharacters;

public void PauseGame()
{
	if (gameCharacters != null)
	{
		gameCharacters.SetActive(false);
	}
}

public void UnPauseGame()
{
	if (gameCharacters != null)
	{
		gameCharacters.SetActive(true);
	   }
     }
 }

Hi @wasicool7. There are many way to do what you want, but is the most simple for me is create new tag for enemy, and call it “Enemy”, the change your code a litle :

// instead of   Instantiate(enemy, spawnPoint, Quaternion.identity);
var Enemy: GameObject = Instantiate(enemy, spawnPoint, Quaternion.identity);
Enemy.tag = "Enemy";

And then change your pause script:

       	public class UIManagerScript : MonoBehaviour {
	public GameObject gameCharacters;
	public void PauseGame()
	{
		if (gameCharacters != null)
		{
			gameCharacters.SetActive(false);
		}
		GameObject[] Enemys = GameObject.FindGameObjectsWithTag ("Enemy");
		for (int i=0;i<Enemys.Length;i++){
			Enemys*.SetActive(false);*
  •   	}*
    
  •   }*
    
  •   public void UnPauseGame()*
    
  •   {*
    
  •   	if (gameCharacters != null)*
    
  •   	{*
    
  •   		gameCharacters.SetActive(true);*
    
  •   	}*
    
  •   	GameObject[] Enemys = GameObject.FindGameObjectsWithTag  ("Enemy");*
    
  •   	for (int y=0;y<Enemys.Length;y++){*
    
  •   		Enemys[y].SetActive(true);*
    
  •   	}*
    
  •   }*
    
  • }*

What about:

public void PauseGame()
{
   Time.timeScale = 0;
}

public void UnPauseGame()
{
   Time.timeScale = 1;
}

Have the instantiated objects deleted on game pause.