yyl
2025-08-29 21488796efae93ab7f074d7ad9bfc9d15d82a182
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using UnityEngine;
 
public class StraightBulletCurve : BulletCurve
{
    private Vector2 start;
    private Vector2 end;
 
    public StraightBulletCurve(BattleObject caster, SkillConfig skillConfig, BattleEffectPlayer bulletEffect, RectTransform target, HB427_tagSCUseSkill tagUseSkillAttack, Action<int, List<HB427_tagSCUseSkill.tagSCUseSkillHurt>> onHit)
        : base(caster, skillConfig, bulletEffect, target, tagUseSkillAttack, onHit)
    { 
        BattleDebug.LogError("StraightBulletCurve created bulletTrans is null = " + (bulletTrans == null).ToString());
    }
 
    public override void Reset()
    {
        base.Reset();
        start = WorldToLocalAnchoredPosition(bulletTrans.position);
        end = WorldToLocalAnchoredPosition(target.position);
 
        // BattleUtility.MarkStartAndEnd(bulletTrans, target);
    }
 
    public override void Run()
    {
        if (finished) return;
 
        if (bulletTrans == null)
        {
            BattleDebug.LogError("BulletTrans is null, cannot run StraightBulletCurve");
            return;
        }
 
        elapsed += Time.deltaTime;
        float t = Mathf.Clamp01(elapsed / duration);
        Vector2 pos = Vector2.Lerp(start, end, t);
        bulletTrans.anchoredPosition = pos;
 
        Vector2 dir = end - start;
        float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
        bulletTrans.localRotation = Quaternion.Euler(0, bulletTrans.transform.localScale.x < 0f ? 180 : 0, angle);
        // if (bulletTrans.transform.localScale.x < 0f)
        // {
        //     bulletTrans.transform.localRotation *= Quaternion.Euler(0, 180, 0);
        // }
        if (t >= 1f)
        {
            finished = true;
            onHit?.Invoke(0, hurts);
        }
    }
}