유니티 카메라 월드포지션 -> 캔버스 포지션
World Position to Canvas Position
//월드 포지션 -> 캔버스 포지션
public Vector2 WorldToCanvasPosition(Camera cam, Vector3 worldPos, RectTransform canvasRect)
{
Vector2 ViewportPosition = cam.WorldToViewportPoint(worldPos);
Vector2 WorldObject_CanvasPosition = new Vector2(
((ViewportPosition.x * canvasRect.sizeDelta.x) - (canvasRect.sizeDelta.x * 0.5f)),
((ViewportPosition.y * canvasRect.sizeDelta.y) - (canvasRect.sizeDelta.y * 0.5f)));
return WorldObject_CanvasPosition;
}
//월드 포지션 -> 캔버스 포지션
public Vector2 WorldToCanvasPosition(Camera cam, Vector3 worldPos, RectTransform canvasRect)
{
Vector2 ViewportPosition = cam.WorldToViewportPoint(worldPos);
Vector2 WorldObject_CanvasPosition = new Vector2(
((ViewportPosition.x * canvasRect.sizeDelta.x) - (canvasRect.sizeDelta.x * 0.5f)),
((ViewportPosition.y * canvasRect.sizeDelta.y) - (canvasRect.sizeDelta.y * 0.5f)));
return WorldObject_CanvasPosition;
}
댓글
댓글 쓰기