Edited at

【Unity】Viewportを利用したWorldPoint(position)の画面外のposition

More than 5 years have passed since last update.


ソースコードの一部抜粋

using UnityEngine;

using System. Collections;

public class GM : MonoBehaviour {

public static Camera mainCamera;

public static float startWorldPointX;
public static float endWorldPointX;
public static float startWorldPointY;
public static float endWorldPointY;

void Start () {

mainCamera = GameObject .FindGameObjectWithTag("MainCamera" ).GetComponent <Camera> ();

// Viewポートの一番左のX座標
GM.startWorldPointX = GM.mainCamera.ViewportToWorldPoint(new Vector3 (0.0f, 1.0f, GM .mainCamera. nearClipPlane)).x;
// Viewポートの一番右のX座標
GM.endWorldPointX = GM.mainCamera.ViewportToWorldPoint(new Vector3 (1.0f, 1.0f, GM .mainCamera. nearClipPlane)).x;
// Viewポートの一番上のY座標
GM.startWorldPointY = GM.mainCamera.ViewportToWorldPoint(new Vector3 (0.0f, 0.0f, GM .mainCamera. nearClipPlane)).y;
// Viewポートの一番下のY座標
GM.endWorldPointY = GM.mainCamera.ViewportToWorldPoint(new Vector3 (0.0f, 1.0f, GM .mainCamera. nearClipPlane)).y;
}

}


参考画像

graphics_fundamentals_viewport_3dscene.png


参考サイト

http://answers.unity3d.com/questions/589485/understanding-3d-world-and-gui-camera-space.html