您的位置:首页 > 移动开发 > Unity3D

Unity3D的世界坐标转化成屏幕坐标

2013-08-27 09:47 288 查看
使用函数:Camera.WorldToScreenPoint

原型:function WorldToScreenPoint (position : Vector3) : Vector3

返回值:Vector3 中 x,y是屏幕中的位置,z是坐标到摄像机的距离 屏幕左下方是(0,0);右上方是(pixelWidth,pixelHeight)

例程:

var target : Transform;  
function Update ()  
{  
var screenPos = camera.WorldToScreenPoint (target.position);  
print ("target is " + screenPos.x + " pixels from the left");  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Unity3D