Esempio n. 1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.layer == 13)
     {
         // Same code as in Bullet.CS
         if (GameObject.Find("Player").GetComponent <Invincible>() == null)
         {
             GameObject.Find("Player").GetComponent <Health>().Amount -= Damage;
             Invincible invincible = GameObject.Find("Player").AddComponent <Invincible>();
             invincible.Duration = InvulnerabilityLength;
             if (GameObject.Find("Player").GetComponent <FlashSpriteRed>() == null)
             {
                 FlashSpriteRed flashRed = GameObject.Find("Player").AddComponent <FlashSpriteRed>();
                 flashRed.Duration    = 0.5f;
                 flashRed.startColor  = new Color(1, 0, 0, 0.125f);
                 flashRed.targetColor = new Color(1, 0, 0, 1f);
             }
             GameObject.Find("Player").GetComponent <Health>().PlayPainSound();
         }
     }
 }
Esempio n. 2
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     // Layer 13 is a collider that is attached to the player for the sole purpose of allowing us to have enemies move through players
     // but still be able to check if enemies and players overlap
     if (collision.gameObject.layer == 13)
     {
         // Same code as in Bullet.CS
         if (GameObject.Find("Player").GetComponent <Invincible>() == null)
         {
             GameObject.Find("Player").GetComponent <Health>().Amount -= Damage;
             Invincible invincible = GameObject.Find("Player").AddComponent <Invincible>();
             invincible.Duration = InvulnerabilityLength;
             if (GameObject.Find("Player").GetComponent <FlashSpriteRed>() == null)
             {
                 FlashSpriteRed flashRed = GameObject.Find("Player").AddComponent <FlashSpriteRed>();
                 flashRed.Duration    = 0.5f;
                 flashRed.startColor  = new Color(1, 0, 0, 0.125f);
                 flashRed.targetColor = new Color(1, 0, 0, 1f);
             }
             GameObject.Find("Player").GetComponent <Health>().PlayPainSound();
         }
     }
 }
Esempio n. 3
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        // Destroy bullet if it hits a wall
        if (collision.gameObject.layer == 12)
        {
            Destroy(this.gameObject);
            return;
        }

        // Make sure required variables are here
        Team   targetTeam   = collision.gameObject.GetComponent <Team>();
        Team   bulletTeam   = this.GetComponent <Team>();
        Health targetHealth = collision.gameObject.GetComponent <Health>();

        if (bulletTeam == null || targetTeam == null || targetHealth == null)
        {
            return;
        }

        // Make sure enemy bullets dont hit enemies and player bullets dont hit players
        if (targetTeam.TeamID != bulletTeam.TeamID)
        {
            // Layer 8 is enemies so this checks if the bullet hit an enemy
            if (collision.gameObject.layer == 8)
            {
                // Check the bullet hit a red dude as thet are the ONLY ONE we can attack
                if (collision.gameObject.GetComponent <CommanderEnemy>() != null && bulletTeam.TeamID != TeamIDs.Turret && collision.gameObject.GetComponent <Invincible>() == null)
                {
                    collision.gameObject.GetComponent <Health>().Amount -= Damage;
                    GameObject.Find("GameManager").GetComponent <ScoreCounter>().Score++;
                }
                else if (collision.gameObject.GetComponent <StatueEnemy>() != null && bulletTeam.TeamID == TeamIDs.Turret && collision.gameObject.GetComponent <Invincible>() == null)
                {
                    // Comment this out to disable turret bullets killing statues
                    collision.gameObject.GetComponent <Health>().Amount -= Damage;
                    Destroy(this.gameObject);
                    // Comment above to disable turret bullets killing statues

                    return;
                }
                if (collision.gameObject.GetComponent <CommanderEnemy>() != null && bulletTeam.TeamID == TeamIDs.Turret)
                {
                    return;
                }
            } // Check if we hit player head collision box
            else
            {
                // Dont deal damage if we are invincible
                if (collision.gameObject.GetComponent <Invincible>() == null)
                {
                    collision.gameObject.GetComponent <Health>().Amount -= Damage;

                    // Give temporary invincibility after being hit
                    Invincible invincible = collision.gameObject.AddComponent <Invincible>();
                    invincible.Duration = InvulnerabilityDuration;
                    // Flash the sprite red to show we got hit
                    if (collision.gameObject.GetComponent <FlashSpriteRed>() == null)
                    {
                        FlashSpriteRed flashRed = collision.gameObject.AddComponent <FlashSpriteRed>();
                        flashRed.Duration    = 0.5f;
                        flashRed.startColor  = new Color(1, 0, 0, 0.125f);
                        flashRed.targetColor = new Color(1, 0, 0, 1f);
                    }
                    collision.gameObject.GetComponent <Health>().PlayPainSound();
                }
            }
            Destroy(this.gameObject);
        }
    }