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. }  
var target : Transform;
function Update ()
{
var screenPos = camera.WorldToScreenPoint (target.position);
print ("target is " + screenPos.x + " pixels from the left");
}


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-09-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2021-07-21
  • 2021-04-23
相关资源
相似解决方案