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


使用函数:Camera.WorldToScreenPoint

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

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

例程:

  1. var target : Transform;  
  2. function Update ()  
  3. {  
  4. var screenPos = camera.WorldToScreenPoint (target.position);  
  5. print ("target is " + screenPos.x + " pixels from the left");  
  6. }  

相关内容