Exemple #1
0
 void Hit(Collider2D c)
 {
     if (isDamagingEnemies && c.gameObject.layer == Alias.LAYER_ENEMIES)
     {
         c.gameObject.GetComponent <EnemyCollider>().OnHitByBullet(damage);
     }
     if (isDamagingShip && c.gameObject.layer == Alias.LAYER_SHIP)
     {
         OnHitPlayerShip?.Invoke(damage);
     }
     if ((isDestroyingEnemyBullets && c.gameObject.layer == Alias.LAYER_ENEMY_PROJECTILES) ||
         (isDestroyingShipBullets && c.gameObject.layer == Alias.LAYER_SHIP_PROJECTILES))
     {
         c.gameObject.GetComponent <Bullet>().OnHitByExplosion();
     }
 }
Exemple #2
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.layer == Alias.LAYER_MAP)
     {
         HitMap(false);
     }
     if (!isEnemyProjectile && col.gameObject.layer == Alias.LAYER_ENEMIES)
     {
         col.gameObject.GetComponent <EnemyCollider>().OnHitByBullet(defaultDamage);
         DestroyMyself();
     }
     else if (isEnemyProjectile && col.gameObject.layer == Alias.LAYER_SHIP)
     {
         OnHitPlayerShip?.Invoke(defaultDamage);
         DestroyMyself();
     }
 }
 void OnCollisionStay2D(Collision2D otherColl)
 {
     //Check if collide with player ship
     if (otherColl.gameObject.layer == Alias.LAYER_SHIP)
     {
         OnHitPlayerShip?.Invoke(info.type, damageToShip * Time.fixedDeltaTime);
         if (healthManager != null)
         {
             healthManager.GotHitByShip();
         }
     }
     //check if collide with map
     else if (otherColl.gameObject.layer == Alias.LAYER_MAP && isMapCollidable)
     {
         if (healthManager != null)
         {
             healthManager.GotMapHit();
         }
     }
 }