게임 개발/유니티

Camera.WorldToScreenPoint

FlowTree 2020. 4. 11. 20:11
반응형

Camera.WorldToScreenPoint

public Vector3 WorldToScreenPoint(Vector3 position);

position의 좌표를 월드 좌표(3D)에서 스크린좌표=화면(2D)로 변환하는 메서드이다.

 

 

예문

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public Transform target;
    Camera camera;
    
    void Start() {
    	camera = GetComponent<Camera>();
    }
    
    void Update() {
    	//target의 position(3D)을 스크린 좌표로 변환하고 좌표를 변수 screenPos에 저장
        Vector3 screenPos = camera.WorldToScreenPoint(target.position);
        Debug.Log("target is " + screenPos.x + " pixels from the left");
    }
}
반응형