void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Enemy") { other.SendMessage("BeHit"); GameObject.Destroy(this.gameObject); } }
然后在enemy脚本中添加BeHit方法
public void BeHit(int hp) { hp -= 1; if (hp<=0) { // GameObject.Instantiate(enemyExpollusion, transform.position, Quaternion.identity); GameObject.Destroy(this.gameObject); } }