diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs index e1ded4c4..b729b0af 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicle.cs @@ -125,7 +125,7 @@ public class UnmannedAerialVehicle : MonoBehaviour + "编号" + serialNumber + "子无人机" + "自杀式攻击自爆了"; UploadLog(_log); } - if(explodePrefab&&transform) + if (explodePrefab && transform) { GameObject Bao = Instantiate(explodePrefab, transform); Bao.transform.localPosition = Vector3.zero; @@ -258,29 +258,29 @@ public class UnmannedAerialVehicle : MonoBehaviour Vector3 _v3 = attackTarget.position; transform.DOLookAt(_v3, 0.1f).OnComplete(() => { - if (wrjModel == WRJModel.光学无人机) - { - Debug.Log("光学无人机攻击"); - StopCoroutine(RangedAttack()); - StartCoroutine(RangedAttack()); - } - else - { + //if (wrjModel == WRJModel.光学无人机) + //{ + // //Debug.Log("光学无人机攻击"); + // //StopCoroutine(RangedAttack()); + // //StartCoroutine(RangedAttack()); + //} + //else + //{ string nowData = GetSyncData(attackTarget); - Debug.Log(nowData); - MyNetMQClient.instance.Send(nowData); - //_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); - //DeviceManager.Instance.send2roomStr.Enqueue(nowData); - //MQTTManager.instance.SendData(MQTTManager.instance.SingleDronePosition, nowData); - float distance = Vector3.Distance(transform.position, attackTarget.position); - transform.DOMove(attackTarget.position, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() => - { + Debug.Log(nowData); + MyNetMQClient.instance.Send(nowData); + //_ = SyncCreateRoom.SendMessageAsync(string.Format("send2room {0}", nowData)); + //DeviceManager.Instance.send2roomStr.Enqueue(nowData); + //MQTTManager.instance.SendData(MQTTManager.instance.SingleDronePosition, nowData); + float distance = Vector3.Distance(transform.position, attackTarget.position); + transform.DOMove(attackTarget.position, distance / FireSpeed).SetEase(Ease.Linear).OnComplete(() => + { //if (!attackTarget) //{ // //BeAssaulted("没有攻击到目标"); //} }); - } + //} }); } } diff --git a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs index 935919ab..8f40f278 100644 --- a/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs +++ b/Assets/Zion/Scripts/ModelFunction/UAV/UnmannedAerialVehicleManage.cs @@ -489,9 +489,15 @@ public class UnmannedAerialVehicleManage : MonoBehaviour public List attackColliders1 = new List(); - - - + + + private bool GetAttackTarget(GameObject c) + { + if (Vector3.Distance(transform.position, c.transform.position) < 500f) + return true; + else + return false; + } /// /// 攻击打击 @@ -501,27 +507,31 @@ public class UnmannedAerialVehicleManage : MonoBehaviour //if (isEngagedTarget) return; //if (wrjModel == WRJModel.电子侦察无人机 || wrjModel == WRJModel.光学无人机) + List allColliders = GameObject.FindGameObjectsWithTag("AttackTarget").ToList().FindAll(GetAttackTarget); if (wrjModel == WRJModel.电子侦察无人机) { - List allColliders = Physics.OverlapSphere(transform.position,500).ToList(); // 检索范围内的所有碰撞体 - + //List allColliders = Physics.OverlapSphere(transform.position,500).ToList(); // 检索范围内的所有碰撞体 for (int i = 0; i < allColliders.Count; i++) { - attackColliders1.Add(allColliders[i]); + if (!attackColliders1.Contains(allColliders[i].GetComponent())) + attackColliders1.Add(allColliders[i].GetComponent()); } } else if (wrjModel == WRJModel.光学无人机) { - List allColliders = Physics.OverlapSphere(transform.position,500).ToList(); // 检索范围内的所有碰撞体 + //List allColliders = Physics.OverlapSphere(transform.position, 500).ToList(); // 检索范围内的所有碰撞体 + //List allColliders = GameObject.FindGameObjectsWithTag("AttackTarget").ToList().FindAll(GetAttackTarget); + for (int i = 0; i < allColliders.Count; i++) { - if (allColliders[i].gameObject.tag == "AttackTarget" && !allColliders[i].isTrigger && !attackColliders1.Contains(allColliders[i])) + if (!allColliders[i].GetComponent().isTrigger && !attackColliders1.Contains(allColliders[i].GetComponent())) { Vector3 pos = gxWRJCamera.WorldToViewportPoint(allColliders[i].transform.position); bool ispcamera = (pos.x > 0 && pos.x < 1 && pos.y > 0 && pos.y < 1 && pos.z > 0); if (ispcamera) { - attackColliders1.Add(allColliders[i]); + if (!attackColliders1.Contains(allColliders[i].GetComponent())) + attackColliders1.Add(allColliders[i].GetComponent()); } } }