Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D col)
    {
        //we hit a smol rock, destroy it
        if (col.tag == "Debris")
        {
            Destroy(this.gameObject);
        }
        //we hit the player, hurt it
        if (col.tag == "Player")
        {
            player.takeDamage(damage);
            player.ActivatePlayerShield(true); //< true because damage was dealt
            Destroy(this.gameObject);
        }
        if (col.tag == "medium" || col.tag == "large")
        {
            Destroy(this.gameObject);
        }

        if (col.gameObject.tag == "TetheredPart")
        {
            TetheredObject tetherObject = col.gameObject.GetComponent <TetheredObject>();
            tetherObject.HandleImpact();
        }
    }
Ejemplo n.º 2
0
 void OnCollisionEnter2D(Collision2D col)
 {
     if (splitactivated)
     {
         Split();
     }
     //if this is a debris object and its colliding with player
     if (gameObject.tag == "Debris")
     {
         //handle player damage and knockback
         if (col.gameObject.tag == "Player")
         {
             Player playerObject = col.gameObject.GetComponent <Player>();
             //calculate damage to deal, knockback is true
             float damageAmount = CalculateAngularDamageAndKnockback(col, true);
             playerObject.takeDamage(damageAmount);
             if (damageAmount > 0)
             {
                 playerObject.ActivatePlayerShield(true);
             }                                         //< true since damage was dealt
             else
             {
                 playerObject.ActivatePlayerShield(false);
             }                                           //< false since no damage dealt
         }
         //handled enemy damage and knockback
         if (col.gameObject.tag == "Enemy")
         {
             EnemyCollision enemyObject;
             if (enemyObject = col.gameObject.GetComponent <EnemyCollision>())
             {
                 //calculate damage to deal, knockback is true
                 enemyObject.TakeDamage(CalculateAngularDamageAndKnockback(col, false));
             }
         }
         if (col.gameObject.tag == "TetheredPart")
         {
             TetheredObject tetherObject = col.gameObject.GetComponent <TetheredObject>();
             //calculate damage to deal, knockback is true
             float damageAmount = CalculateAngularDamageAndKnockback(col, false);
             //if the damage is over a limit, cause a hit to the tether object
             if (damageAmount > 10)
             {
                 tetherObject.HandleImpact();
             }
         }
     }
 }