(client) feat:实现子弹的生成
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user