找回密碼
 注冊帳號

掃一掃,訪問微社區

camera.worldtoviewportpoint 世界轉視窗位置

2015-1-4 09:07| 發布者: 楊炎| 查看: 3267| 評論: 0|原作者: 蠻牛|來自: unity3d腳本manual

摘要: camera.worldtoviewportpoint 世界轉視窗位置functionworldtoviewportpoint(position:vector3description描述transforms position from world space into viewport space.從世界空間到視窗空間的變換位置。viewport ...

camera.worldtoviewportpoint 世界轉視窗位置

functionworldtoviewportpoint(position:vector3

description描述

transforms position from world space into viewport space.

從世界空間到視窗空間的變換位置。

viewport space is normalized and relative to the camera. the bottom-left of the camera is (0,0); the top-right is (1,1). the z position is in world units from the camera.

視口空間是歸一化的并相對于相機的。相機的左下為(0,0);右上是(1,1),z的位置是以世界單位衡量的到相機的距離。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

publictransformtarget;

void update() {

vector3viewpos = camera.worldtoviewportpoint(target.position);

if (viewpos.x > 0.5f)

print("target is on the right side!");

else

print("target is on the left side!");

}

}

// finds out whether target is on the left or right side of the screen

//target在屏幕的左邊還是右邊

var target :transform;

function update () {

var viewpos :vector3= camera.worldtoviewportpoint (target.position);

// viewport coordinates range from zero to one

//視口坐標范圍從0到1

if( viewpos.x > 0.5 )

print ("target is on the right side!");

else

print ("target is on the left side!");

}

相關閱讀

文章點評
相關文章
女校游泳队彩金