using UnityEngine; using UnityEngine.UI; public class AimArrowController : MonoBehaviour { public Image arrow; 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; } 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; Shoot(); } } public void OnAimStart(Vector2 screenPos) { UpdateArrow(screenPos); } public void OnAimDrag(Vector2 screenPos) { UpdateArrow(screenPos); } void Shoot() { if (IngameMgr.Ins.Get_SkillValue(eSkillType.PreviousArrow) > 0) Shoot_PreviousArrow(); else Shoot_Normal(); } void Shoot_Normal() { var unit = IngameMgr.Ins.Get_CurUnitTData(); 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), tf_Start = arrow.transform, PreviousArrow = 0, Dmg = (int)attack }); } void Shoot_PreviousArrow() { var unit = IngameMgr.Ins.Get_CurUnitTData(); var attack = unit.n_DefaultAttack + IngameMgr.Ins.Get_SkillValue(eSkillType.AttackUp); int prev = (int)IngameMgr.Ins.Get_SkillValue(eSkillType.PreviousArrow); int total = prev + 1; for (int i = 0; i < total; i++) { ProjectileMgr.Ins.Shoot_Projectile(new ProjectileData { IsPC = true, PreviousArrow = prev, ArrowIndex = i, m_Data = table_projectile.Ins.Get_Data(unit.n_ProjectileID), tf_Start = arrow.transform, Dmg = (int)attack }); } } void UpdateArrow(Vector2 currentPos) { Vector2 dir = currentPos - (Vector2)arrow.transform.position; 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); } }