using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; /// /// 无人机 /// public class UnmannedAerialVehicle : MonoBehaviour { /// /// 所属无人机蜂群 /// public UnmannedAerialVehicleManage unmannedAerialVehicleManage; #region 无人机数据 /// /// 续航时间 /// public string batteryLife; /// /// 抗风等级 /// public string classificationWindResistance; /// /// 最大飞行速度 /// public string maximumFlyingSpeed; /// /// RCS /// public string RCS; /// /// 卫星定位频点 /// public string satellitePositioningFrequency; /// /// 数据链通信频点 /// public string dataLinkCommunicationFrequency; /// /// 电子侦察能力 /// public string electronicReconnaissanceCapability; /// /// 光学侦察能力 /// public string opticalReconnaissanceCapability; #endregion /// /// 飞行速度 /// public float FireSpeed = 20.0f; /// /// 检测范围半径 /// public float detectionRadius = 50; // /// /// 是否正在攻击目标 /// private bool isEngagedTarget = false; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (unmannedAerialVehicleManage) { switch (unmannedAerialVehicleManage.pattern) { case Pattern.待机: break; case Pattern.警戒: //AttackATarget(); break; case Pattern.攻击: //AttackATarget(); break; } } } /// /// 攻击目标 /// public void AttackATarget() { if (!isEngagedTarget) { Collider[] colliders = Physics.OverlapSphere(transform.position, detectionRadius); // 检索范围内的所有碰撞体 foreach (Collider col in colliders) { //Debug.Log("检测到Gongjimubiao: " + col.name); if (col.transform.tag == "AttackTarget") { Debug.Log(col.transform.name); AttAck(col.transform); isEngagedTarget = true; } } } } /// /// 发起攻击 /// private void AttAck(Transform target) { Debug.Log("开始攻击目标..:" + target.name); transform.DOLookAt(target.position, 0.1f).OnComplete(() => { float distance = Vector3.Distance(transform.position, target.position); transform.DOMove(target.position, distance / FireSpeed); }); } private void OnTriggerEnter(Collider other) { if (other.tag == "AttackTarget") { // 销毁objectToDestroy对象 Destroy(transform.gameObject); } } /// /// 被攻击 /// /// public void BeAssaulted(string type) { switch (type) { case "激光打击": Destroy(gameObject); break; case "无线电干扰": Destroy(gameObject); break; default: break; } } void OnDestroy() { transform.DOKill(); Debug.Log("被销毁了"); } }