//收到击中协议 public static void OnMsgHit(MsgBase msgBase) { MsgHit msg = (MsgHit)msgBase; //查找坦克 BaseTank tank = GetTank(msg.targetId); if (tank == null) { return; } bool isDie = tank.IsDie(); //被击中 tank.Attacked(msg.damage); //击杀提示 if (!isDie && tank.IsDie() && msg.id == GameMain.id) { PanelManager.Open <KillPanel>(); } }
//碰撞 void OnCollisionEnter(Collision collisionInfo) { //打到的坦克 GameObject collObj = collisionInfo.gameObject; BaseTank hitTank = collObj.GetComponent <BaseTank>(); //不能打自己 if (hitTank == tank) { return; } //打到其他坦克 if (hitTank != null) { hitTank.Attacked(35); } //显示爆炸效果 GameObject explode = ResManager.LoadPrefab("fire"); Instantiate(explode, transform.position, transform.rotation); //摧毁自身 Destroy(gameObject); }