(client) feat:实现子弹的生成

This commit is contained in:
m0_75251201
2025-08-17 11:16:55 +08:00
parent 12a4f9efaa
commit ed7ecdb226
22 changed files with 436 additions and 182 deletions

View File

@ -3,8 +3,14 @@ using UnityEngine;
namespace Entity
{
public class Bullet:Entity
public class Bullet : Entity
{
public override void SetTarget(Vector3 pos)
{
base.SetTarget(pos);
RotateTransformToDirection(transform, direction);
}
protected override void AutoBehave()
{
TryMove();
@ -13,6 +19,19 @@ namespace Entity
private void OnTriggerEnter2D(Collider2D other)
{
other.GetComponent<Entity>()?.OnHit(this);
attributes.health -= 1;
}
// 旋转对象到指定方向
public static void RotateTransformToDirection(Transform transform, Vector3 targetDirection)
{
// 默认向上方向
Vector3 upDirection = Vector3.up;
// 计算旋转角度
float angle = Mathf.Atan2(targetDirection.x, targetDirection.y) * Mathf.Rad2Deg;
// 设置旋转
transform.rotation = Quaternion.Euler(0, 0, angle);
}
}
}