mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 06:47:14 +08:00
Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com> Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/60
22 lines
653 B
C#
22 lines
653 B
C#
using UnityEngine;
|
|
|
|
namespace Utils
|
|
{
|
|
public static class RotateTool
|
|
{
|
|
// 旋转对象到指定方向
|
|
|
|
public static float RotateTransformToDirection(Transform transform, Vector3 targetDirection)
|
|
{
|
|
// 确保目标方向不是零向量
|
|
if (targetDirection == Vector3.zero)
|
|
return 0;
|
|
|
|
// 计算当前向上方向与目标方向之间的角度
|
|
var angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg;
|
|
// 应用旋转
|
|
transform.rotation = Quaternion.Euler(0f, 0f, angle);
|
|
return angle;
|
|
}
|
|
}
|
|
} |