OneShotOneKill/Assets/Script/InGame/Actor/AimArrowController.cs

69 lines
1.7 KiB
C#
Raw Normal View History

using UnityEngine;
using UnityEngine.UI;
public class AimArrowController : MonoBehaviour
{
public Image arrow;
2026-01-11 23:53:38 +00:00
public Transform projectileParent;
float m_attackTime, m_attackLifeTime;
void Start()
{
//arrow.enabled = false;
}
private void OnEnable()
{
var unit = IngameMgr.Ins.Get_CurUnitTData();
m_attackLifeTime = m_attackTime = unit.f_AttackSpeed;
}
2026-01-14 07:29:45 +00:00
public void Set_AttackLifeTime()
{
var unit = IngameMgr.Ins.Get_CurUnitTData();
m_attackLifeTime = unit.f_AttackSpeed - IngameMgr.Ins.Get_SkillValue(eSkillType.AttackSpeedUp);
}
private void Update()
{
m_attackLifeTime -= Time.deltaTime;
if (m_attackLifeTime <= 0)
{
m_attackLifeTime = m_attackTime;
2026-01-14 04:49:44 +00:00
Shoot();
}
}
public void OnAimStart(Vector2 screenPos)
{
UpdateArrow(screenPos);
}
public void OnAimDrag(Vector2 screenPos)
{
UpdateArrow(screenPos);
}
2026-01-14 04:49:44 +00:00
void Shoot()
{
2026-01-13 00:46:52 +00:00
var unit = IngameMgr.Ins.Get_CurUnitTData();
2026-01-14 07:24:45 +00:00
var attack = unit.n_DefaultAttack + IngameMgr.Ins.Get_SkillValue(eSkillType.AttackUp);
ProjectileMgr.Ins.Shoot_Projectile(new ProjectileData
{
IsPC = true,
m_Data = table_projectile.Ins.Get_Data(unit.n_ProjectileID),
2026-01-13 07:33:06 +00:00
tf_Start = arrow.transform,
2026-01-14 07:24:45 +00:00
Dmg = (int)attack
});
}
void UpdateArrow(Vector2 currentPos)
{
2026-01-14 04:49:44 +00:00
Vector2 dir = currentPos - (Vector2)arrow.transform.position;
2026-01-14 04:49:44 +00:00
float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 45f) * 7.5f;
angle = Mathf.Clamp(angle, -80f, 80f);
arrow.rectTransform.rotation = Quaternion.Euler(0, 0, angle);
}
}