mirror of
http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite.git
synced 2025-11-20 05:17:13 +08:00
21 lines
632 B
C#
21 lines
632 B
C#
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace Utils
|
||
|
|
{
|
||
|
|
public static class RotateTool
|
||
|
|
{
|
||
|
|
// 旋转对象到指定方向
|
||
|
|
|
||
|
|
public static void RotateTransformToDirection(Transform transform, Vector3 targetDirection)
|
||
|
|
{
|
||
|
|
// 确保目标方向不是零向量
|
||
|
|
if (targetDirection == Vector3.zero)
|
||
|
|
return;
|
||
|
|
|
||
|
|
// 计算当前向上方向与目标方向之间的角度
|
||
|
|
var angle = Mathf.Atan2(targetDirection.y, targetDirection.x) * Mathf.Rad2Deg;
|
||
|
|
// 应用旋转
|
||
|
|
transform.rotation = Quaternion.Euler(0f, 0f, angle);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|