반응형
public class HoborController : MonoBehaviour
{
[SerializeField] Image image;
[SerializeField] Transform cube;
[SerializeField] Camera camera;
// Update is called once per frame
void Update()
{
// Debug.Log($"{camera.WorldToScreenPoint(cube.position)}");
image.transform.position = camera.WorldToScreenPoint(cube.position);
}
}
WorldToScreenPoint 함수는 World의 좌표를 Canvas의 좌표로 변환시켜줌
Canvs의 RenderMode가 Screen Space - Overay일 경우에 사용가능
Camra의 FOV 밖으로 나가면 Canvas에 표시되지 않음
Unity - 스크립팅 API: Camera.WorldToScreenPoint
스크린 좌표는 픽셀 단위로 정의되어 있습니다. 화면 왼쪽 하단은 (0,0), 오른쪽 상단은 is (pixelWidth,pixelHeight). The z position is in world units from the camera.
docs.unity3d.com
반응형
'Unity > Unity 리서치' 카테고리의 다른 글
CameraShake (카메라 흔들기) (0) | 2021.07.26 |
---|---|
Animation Override Controller (0) | 2021.07.17 |
RectTransform의 width, height 알아내기 (0) | 2021.07.13 |
영상(Video Player) 재생 (1) | 2021.07.12 |
Loading Scnene 구현 (0) | 2021.07.12 |