드디어 완성
This commit is contained in:
36
Assets/02_Scripts/Story/ch3/XRMoveToPoint.cs
Normal file
36
Assets/02_Scripts/Story/ch3/XRMoveToPoint.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
using Unity.XR.CoreUtils;
|
||||
|
||||
public class XRMoveToPoint : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private XROrigin xrOrigin;
|
||||
[SerializeField] private Transform targetPoint;
|
||||
|
||||
public void MoveNow()
|
||||
{
|
||||
if (xrOrigin == null || targetPoint == null)
|
||||
return;
|
||||
|
||||
// 현재 카메라를 목표 위치로 이동
|
||||
xrOrigin.MoveCameraToWorldLocation(targetPoint.position);
|
||||
|
||||
// 카메라가 목표 지점의 앞 방향을 바라보게 회전
|
||||
Vector3 currentForward = xrOrigin.Camera.transform.forward;
|
||||
currentForward.y = 0f;
|
||||
|
||||
Vector3 targetForward = targetPoint.forward;
|
||||
targetForward.y = 0f;
|
||||
|
||||
if (currentForward.sqrMagnitude > 0.001f &&
|
||||
targetForward.sqrMagnitude > 0.001f)
|
||||
{
|
||||
float angle = Vector3.SignedAngle(
|
||||
currentForward,
|
||||
targetForward,
|
||||
Vector3.up
|
||||
);
|
||||
|
||||
xrOrigin.RotateAroundCameraUsingOriginUp(angle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user