// 触发器事件 private void OnTriggerEnter2D(Collider2D collision) { switch (collision.tag) { // 击中玩家 case "Tank": if (!createdByPlayer) { Player player = collision.GetComponent <Player>(); player.Died(); Destroy(gameObject); } break; // 击中敌人 case "Enemy": if (createdByPlayer) { Enemy enemy = collision.GetComponent <Enemy>(); enemy.Died(); Destroy(gameObject); PlayerManager.Instance.AddScore(enemy.score); } break; // 可销毁的墙体 case "Wall": Destroy(collision.gameObject); Destroy(gameObject); break; // 不可销毁的障碍 case "Barrier": // 仅玩家子弹有效 if (createdByPlayer) { Barrier barrier = collision.GetComponent <Barrier>(); barrier.playHitAudio(); // 最大火力可以摧毁障碍物 if (Player.MAX_FILE_LEVEL == fireLevel) { Destroy(collision.gameObject); } } Destroy(gameObject); break; // 不可销毁的障碍 case "AirBarrier": // 仅玩家子弹有效 if (createdByPlayer) { Barrier barrier = collision.GetComponent <Barrier>(); barrier.playHitAudio(); } Destroy(gameObject); break; // 总部 case "HQ": HQ hq = collision.GetComponent <HQ>(); Destroy(gameObject); hq.Died(); break; // 子弹相互消耗 case "Bullet": Destroy(gameObject); Destroy(collision.gameObject); break; } }