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

スクリプト言語

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

Camera.ScreenPointToRay

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

パラメーター

説明

スクリーンの点を通してカメラからカメラからレイを通します。

結果として得られたレイはワールド空間でカメラの近平面から始まり スクリーンの位置( x, y )ピクセル座標に向けて向かいます。( position.z は無視されます。)

スクリーンスペースはピクセルで定義されています。左下の画面が(0, 0)、右上が( pixelWidthpixelHeight )です。

	// Draws a line in the scene view going through a point 200 pixels
	// from the lower-left corner of the screen
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { Camera camera; void Start() { camera = GetComponent<Camera>(); } void Update() { Ray ray = camera.ScreenPointToRay(new Vector3(200, 200, 0)); Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow); } }