title: Unity3D Shooter - How to switch to next level after all enemies get destroyed?
body: <p>I am a newbie to Unity and I am trying to build a little shooter 2d game in C#. I am now stuck and confess that I am a little lost not knowing what the best approach is, but the problem is that my hero shoots at the enemies and they die but how do I get to the next level after the enemies are all dead? If I make a dead counter, what script do I put in? In the enemy script? Or do I make a new script but associate it with what? I also need the game to end if the hero fires his six bullets (already have a counter that makes the hero not shoot anymore after six shoots) and there are still enemies left ...
  Does anyone give me some tips? Thanks!</p>
  
  <p>Enemy script:</p>
  
  <pre><code>  using System.Collections.Generic;
    using UnityEngine;
  
    public class BadguyScript : MonoBehaviour
    {
        public int maxHealth;
        public int curHealth;
        private Animator myAnimator;
        private bool isDead;
        [SerializeField]
        private float DespawnTime = 2.5f;
        [SerializeField]
        private string DeathAnimHash = "isDead"; 
  
        void Start()
        {
            myAnimator = GetComponent&lt;Animator&gt;();
            myAnimator.enabled =true;
            myAnimator.SetBool (DeathAnimHash ,isDead);
  
  
            maxHealth = 1;
            curHealth = maxHealth;
  
        }
        void Update()
        {
            if (curHealth &lt; 1)
            {
                isDead = true;
                myAnimator.SetBool (DeathAnimHash ,isDead);
                Destroy(gameObject,DespawnTime);
            }
        }
        void OnTriggerEnter2D(Collider2D col)
        {
            if (isDead)
               return;
            if (col.tag == "bullet")
            {
                curHealth -= 1;
                Destroy(col.gameObject);
            }
        }
    }
  </code></pre>
  
  <p>Count Bullets Script:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  
  public class GameFlow : MonoBehaviour
  {
  
      public static float remainingShots = 6;
      public Transform shot1;
      public Transform shot2;
      public Transform shot3;
      public Transform shot4;
      public Transform shot5;
      public Transform shot6;
  
      // Start is called before the first frame update
      void Start()
      {
  
      }
  
      // Update is called once per frame
      void Update()
      {
        if (remainingShots &gt; 0)
        {
          shot1.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot1.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
        if (remainingShots &gt; 1)
        {
          shot2.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot2.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
        if (remainingShots &gt; 2)
        {
          shot3.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot3.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
        if (remainingShots &gt; 3)
        {
          shot4.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot4.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
        if (remainingShots &gt; 4)
        {
          shot5.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot5.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
        if (remainingShots &gt; 5)
        {
          shot6.GetComponent&lt;Image&gt; ().enabled = true;
        }
        else
        {
          shot6.GetComponent&lt;Image&gt; ().enabled = false;
        }
  
  
        if(Input.GetButtonDown("Fire1"))
        {
        remainingShots -= 1;
        }
      }
  }
  </code></pre>