Beispiel #1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("PlayerBullet"))
        {
            Bullet bullet = other.GetComponent <Bullet>();
            // take dmg
            healthComponent.Hit(bullet.damage);

            if (healthComponent.Hp > 0)   // hit
            {
                if (audioSource != null)
                {
                    audioSource.PlayOneShot(playerSounds.explodeEnemy, 1.7f);
                }

                NetworkServer.Destroy(other.gameObject);
            }
            else     // dead
            {
                CmdKilledEnemy(bullet.playerNumber);
                NW_GameLogic.Instance.DestroyedEnemy();
                NetworkServer.Destroy(other.gameObject);
                NetworkServer.Destroy(gameObject);
            }
        }

        if (other.tag == "Base")
        {
            CmdKilledEnemy(-1);;  // -1 means it hits the base
            NetworkServer.Destroy(gameObject);
        }
    }
 private void Collide(Collision2D collision)
 {
     if (collision.collider.gameObject.layer == 10)
     {
         _hp.Hit(1);
     }
 }