歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Unity3D的世界坐標轉化成屏幕坐標

Unity3D的世界坐標轉化成屏幕坐標

日期:2017/3/1 10:24:30   编辑:Linux編程

使用函數: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. }
Copyright © Linux教程網 All Rights Reserved