86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using System;
|
||
using System.Collections;
|
||
using DarkTonic.MasterAudio;
|
||
using DG.Tweening;
|
||
using DragonLi.Core;
|
||
using UnityEngine;
|
||
|
||
public class DeathSwordProjectile : MonoBehaviour
|
||
{
|
||
[Header("Throw")]
|
||
[NonSerialized]
|
||
public float flyTime = 3f;
|
||
public float arcHeight = 2f;
|
||
|
||
[Header("Lightning Area")]
|
||
public GameObject lightningAreaPrefab;
|
||
public float lightningDuration = 5f;
|
||
|
||
private float damage;
|
||
private Action onFinish;
|
||
private Transform originPoint;
|
||
|
||
private Vector3 originPos;
|
||
private Quaternion originRot;
|
||
|
||
public void Init(
|
||
Transform origin,
|
||
Vector3 targetPos,
|
||
float atk,
|
||
Action onFinishCallback
|
||
)
|
||
{
|
||
originPoint = origin;
|
||
originPos = origin.position;
|
||
originRot = origin.rotation;
|
||
damage = atk;
|
||
onFinish = onFinishCallback;
|
||
|
||
StartCoroutine(ThrowRoutine(targetPos.ReflectVectorXOZ()));
|
||
}
|
||
|
||
IEnumerator ThrowRoutine(Vector3 target)
|
||
{
|
||
// 1️⃣ 抛射(DOTween 弧线)
|
||
transform.DOJump(
|
||
target,
|
||
arcHeight,
|
||
1,
|
||
flyTime
|
||
);
|
||
|
||
yield return new WaitForSeconds(flyTime);
|
||
|
||
// 2️⃣ 插入地面
|
||
transform.eulerAngles = Vector3.zero;
|
||
transform.position=transform.position.ReflectVectorXOZ();
|
||
GameManager.Ins.PlaySound3D("1.60",transform,true);
|
||
// 3️⃣ 生成雷电区域
|
||
GameObject area = Instantiate(
|
||
lightningAreaPrefab,
|
||
transform.position,
|
||
Quaternion.identity
|
||
);
|
||
|
||
area.GetComponent<LightningDamageArea>().Init(damage);
|
||
|
||
// 4️⃣ 等待雷电结束
|
||
yield return new WaitForSeconds(lightningDuration);
|
||
MasterAudio.StopAllSoundsOfTransform(area.transform);
|
||
Destroy(area);
|
||
|
||
// 5️⃣ 飞回 Boss
|
||
yield return ReturnToBoss();
|
||
}
|
||
|
||
IEnumerator ReturnToBoss()
|
||
{
|
||
transform.DORotateQuaternion(originRot, 0.3f);
|
||
transform.DOMove(originPos, 0.5f);
|
||
|
||
yield return new WaitForSeconds(0.5f);
|
||
|
||
onFinish?.Invoke();
|
||
Destroy(gameObject);
|
||
}
|
||
} |