Files
valheim/Assets/_Valheim/Scripts/UI/CanvasFaceToCamera.cs
2025-07-04 14:16:14 +08:00

29 lines
689 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DragonLi.Frame;
using DragonLi.Core;
using UnityEngine;
namespace Valheim
{
public class CanvasFaceToCamera : MonoBehaviour
{
private void Update()
{
UpdateRotation();
}
private void UpdateRotation()
{
Vector3 directionToCamera = GameInit.Ins.MRCamera.transform.position - this.transform.position;
directionToCamera.y = 0;
// 计算新的旋转方向固定Y轴方向
Quaternion targetRotation = Quaternion.LookRotation(directionToCamera, Vector3.up);
// 应用新的旋转方向
this.transform.rotation = targetRotation;
}
}
}