A物体在NGUI空间,父节点C,B物体在Unity3d空间。AC的渲染相机为camera2d,B的渲染相机为camera3d,如果我们希望把A物体设置在B物体上面10像素的位置上,但是A物体仍旧在NGUI空间,可以如下设置:
Vector3 result = Vector3.zero;
Vector3 screen3dPos = camera3d.WorldToScreenPoint(B.position);
result = camera2d.ScreenToWorldPoint(screen3dPos);
result.z = 0;
result = c.InverseTransformPoint(result);
result.y += 10;
A.localpostion = result;
原文地址:http://568464209.blog.51cto.com/7726521/1792352