Version: 2017.1
public Ray ScreenPointToRay (Vector3 position);

説明

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

Resulting ray is in world space, starting on the near plane of the camera and going through position's (x,y) pixel coordinates on the screen (position.z is ignored).

スクリーンスペースはピクセルで定義されています。左下の画面が(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 cam;

void Start() { cam = GetComponent<Camera>(); }

void Update() { Ray ray = cam.ScreenPointToRay(new Vector3(200, 200, 0)); Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow); } }