157 lines
3.8 KiB
C#
157 lines
3.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using DG.Tweening;
|
|
|
|
/// <summary>
|
|
/// 无人机
|
|
/// </summary>
|
|
public class UnmannedAerialVehicle : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// 所属无人机蜂群
|
|
/// </summary>
|
|
public UnmannedAerialVehicleManage unmannedAerialVehicleManage;
|
|
|
|
#region 无人机数据
|
|
/// <summary>
|
|
/// 续航时间
|
|
/// </summary>
|
|
public string batteryLife;
|
|
/// <summary>
|
|
/// 抗风等级
|
|
/// </summary>
|
|
public string classificationWindResistance;
|
|
/// <summary>
|
|
/// 最大飞行速度
|
|
/// </summary>
|
|
public string maximumFlyingSpeed;
|
|
/// <summary>
|
|
/// RCS
|
|
/// </summary>
|
|
public string RCS;
|
|
/// <summary>
|
|
/// 卫星定位频点
|
|
/// </summary>
|
|
public string satellitePositioningFrequency;
|
|
/// <summary>
|
|
/// 数据链通信频点
|
|
/// </summary>
|
|
public string dataLinkCommunicationFrequency;
|
|
/// <summary>
|
|
/// 电子侦察能力
|
|
/// </summary>
|
|
public string electronicReconnaissanceCapability;
|
|
/// <summary>
|
|
/// 光学侦察能力
|
|
/// </summary>
|
|
public string opticalReconnaissanceCapability;
|
|
#endregion
|
|
/// <summary>
|
|
/// 飞行速度
|
|
/// </summary>
|
|
public float FireSpeed = 20.0f;
|
|
/// <summary>
|
|
/// 检测范围半径
|
|
/// </summary>
|
|
public float detectionRadius = 50; //
|
|
/// <summary>
|
|
/// 是否正在攻击目标
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 攻击目标
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发起攻击
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 被攻击
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
public void BeAssaulted(string type)
|
|
{
|
|
switch (type) {
|
|
case "激光打击":
|
|
Destroy(gameObject);
|
|
break;
|
|
case "无线电干扰":
|
|
Destroy(gameObject);
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnDestroy()
|
|
{
|
|
transform.DOKill();
|
|
Debug.Log("被销毁了");
|
|
}
|
|
}
|