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

54 lines
1.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class AimArrowController : MonoBehaviour
{
public Image arrow;
public float m_AngleSpeed = 1.5f;
public Transform projectileParent;
Vector2 startPos;
bool isAiming;
void Start()
{
arrow.enabled = false;
}
public void OnAimStart(Vector2 screenPos)
{
isAiming = true;
arrow.enabled = true;
UpdateArrow(screenPos);
}
public void OnAimDrag(Vector2 screenPos)
{
if (!isAiming) return;
UpdateArrow(screenPos);
}
public void OnAimEnd()
{
arrow.enabled = false;
isAiming = false;
var unit = IngameMgr.Ins.Get_CurUnitTData();
ProjectileMgr.Ins.Shoot_Projectile(new ProjectileData
{
IsPC = true,
m_Data = table_projectile.Ins.Get_Data(unit.n_ProjectileID),
tf_Start = arrow.transform
});
}
void UpdateArrow(Vector2 currentPos)
{
Vector2 dir = currentPos - startPos;
if (dir.sqrMagnitude < 0.001f) return;
float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg - 45f) * m_AngleSpeed;
angle = Mathf.Clamp(angle, -60f, 60f);
arrow.rectTransform.rotation = Quaternion.Euler(0, 0, angle);
}
}