Version: 5.3 (switch to 5.4b)
言語English
  • C#
  • JS

スクリプト言語

好きな言語を選択してください。選択した言語でスクリプトコードが表示されます。

Camera.WorldToScreenPoint

マニュアルに切り替える
public Vector3 WorldToScreenPoint(Vector3 position);

パラメーター

説明

ワールド空間の position をスクリーン空間に変換します。

スクリーン座標はピクセル単位で定義されています。画面の左下は(0, 0)、右上は 右上は ( pixelWidthpixelHeight) になります。Z 位置はワールドユニットでカメラからの距離になります。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Transform target; Camera camera; void Start() { camera = GetComponent<Camera>(); } void Update() { Vector3 screenPos = camera.WorldToScreenPoint(target.position); Debug.Log("target is " + screenPos.x + " pixels from the left"); } }