private void OnTriggerEnter2D(Collider2D collision) { string layername = LayerMask.LayerToName(collision.gameObject.layer); if (!layername.Equals("bullet(Player)")) { return; } Transform playerBulletTransform = collision.transform.parent; bullet bullet = playerBulletTransform.GetComponent <bullet>(); hp = hp - bullet.power; Destroy(collision.gameObject); if (hp <= 0) { FindObjectOfType <Score>().AddPoints(points); spaceship.Explosion(); Destroy(gameObject); } else { spaceship.GetAnimator().SetTrigger("Damage"); } }
private void OnTriggerEnter2D(Collider2D collision) { string layername = LayerMask.LayerToName(collision.gameObject.layer); if (layername.Equals("bullet(Enemy)")) { Destroy(collision.gameObject); } if (layername.Equals("bullet(Enemy)") || layername.Equals("enemy")) { FindObjectOfType <manager>().GameOver(); FindObjectOfType <Score>().Save(); spaceship.Explosion(); Destroy(gameObject); } }