This commit is contained in:
YangHua 2024-01-21 13:14:42 +08:00
parent a306bcad2c
commit 184a763763
3 changed files with 14 additions and 6 deletions

View File

@ -7,6 +7,7 @@ public class ShellBoom : MonoBehaviour
{ {
public UnityEvent onShellAttack = new UnityEvent(); public UnityEvent onShellAttack = new UnityEvent();
public bool isPlayer = false; public bool isPlayer = false;
public Transform attackTarget;
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
Debug.Log(other.gameObject.name); Debug.Log(other.gameObject.name);
@ -15,4 +16,11 @@ public class ShellBoom : MonoBehaviour
onShellAttack?.Invoke(); onShellAttack?.Invoke();
} }
} }
private void Update()
{
if (attackTarget != null)
{
transform.Translate(transform.forward * Time.deltaTime * 70f, Space.World);
}
}
} }

View File

@ -210,8 +210,8 @@ public class UnmannedAerialVehicle : MonoBehaviour
if (wrjModel == WRJModel.) if (wrjModel == WRJModel.)
{ {
Debug.Log("光学无人机攻击"); Debug.Log("光学无人机攻击");
//StopCoroutine(RangedAttack()); StopCoroutine(RangedAttack());
//StartCoroutine(RangedAttack()); StartCoroutine(RangedAttack());
} }
else else
{ {
@ -235,12 +235,11 @@ public class UnmannedAerialVehicle : MonoBehaviour
{ {
while (attackTarget) while (attackTarget)
{ {
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.8f);
GameObject obj = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation); GameObject obj = Instantiate(bulletPrefab, bulletPoint.position, bulletPoint.rotation);
obj.SetActive(true); obj.SetActive(true);
Rigidbody rb = obj.GetComponent<Rigidbody>();
rb.AddForce(bulletPoint.forward * 20f, ForceMode.Impulse);
ShellBoom sb = obj.AddComponent<ShellBoom>(); ShellBoom sb = obj.AddComponent<ShellBoom>();
sb.attackTarget = attackTarget;
sb.isPlayer = unmannedAerialVehicleManage.equipmentCommon.isPlayer; sb.isPlayer = unmannedAerialVehicleManage.equipmentCommon.isPlayer;
sb.onShellAttack.AddListener(() => sb.onShellAttack.AddListener(() =>
{ {

View File

@ -305,7 +305,8 @@ public class UnmannedAerialVehicleManage : MonoBehaviour
} }
if (unmannedAerialVehicles[0].attackTarget == null) if (unmannedAerialVehicles[0].attackTarget == null)
{ {
SendMsg(c.transform); if (c != null)
SendMsg(c.transform);
unmannedAerialVehicles[0].AttAck(c.transform); unmannedAerialVehicles[0].AttAck(c.transform);
} }
} }