Ejemplo n.º 1
0
 // Despawns bullets when they leave the bounds of the screen.
 // Deactivates enemy powers (like shooting) when they leave the screen.
 private void OnCollisionExit2D(Collision2D coll)
 {
     if (coll.gameObject.tag.Equals("PlayerBullet") || coll.gameObject.tag.Equals("EnemyBullet"))
     {
         coll.gameObject.SetActive(false);
     }
     if (coll.gameObject.tag.Equals("GroundEnemy") || coll.gameObject.tag.Equals("AirEnemy"))
     {
         Exploder exp = coll.gameObject.GetComponent <Exploder>();
         EnemyAim nma = coll.gameObject.GetComponent <EnemyAim>();
         Tank     tnk = coll.gameObject.GetComponent <Tank>();
         Cannon   can = coll.gameObject.GetComponent <Cannon>();
         if (exp)
         {
             exp.StopShoot();
         }
         if (nma)
         {
             nma.StopShoot();
         }
         if (tnk)
         {
             tnk.StopShoot();
         }
         if (can)
         {
             can.StopShoot();
         }
         // If an enemy was left alive, decrease the threat level.
         ThreatLevel.instance.AddKillLevel(-1f);
     }
 }
Ejemplo n.º 2
0
    // If destroyed, then stop shooting, stop moving, and set the flags to indicate destruction.
    private void DestroyCheck()
    {
        if (health <= 0 && !destroyed)
        {
            destroyed    = true;
            coll.enabled = false;
            sr.sprite    = destroySprite;
            // Disable shooting.
            Exploder exp = GetComponent <Exploder>();
            EnemyAim nma = GetComponent <EnemyAim>();
            Tank     tnk = GetComponent <Tank>();
            Cannon   can = GetComponent <Cannon>();

            if (exp)
            {
                exp.StopShoot();
            }
            if (nma)
            {
                nma.StopShoot();
            }
            if (tnk)
            {
                tnk.StopShoot();
            }
            if (can)
            {
                can.StopShoot();
            }

            // Display the explosion effect.
            FXManager.instance.ShowFX("explosion", transform.position, transform.localScale);
            // Add to score.
            ScoreManager.instance.AddScore(pointsOnDestroy);

            SFXManager.instance.PlayClip("destroy");

            // Make note of it with the Threat Level.
            ThreatLevel.instance.AddKillLevel(1 / 2f);
        }
    }