unity中的坐标转换
2015-10-27 14:16
621 查看
3D坐标->3D坐标
比如现在需要在一个用3D摄像机渲染的物体(用A表示)的相对坐标为(10,-5,91)的地方放置一个物体(用B表示),则B的世界坐标为
3D坐标->2D坐标
比如现在有一个用3D摄像机渲染的物体(用A表示),想在他的看起来的位置上方一个NGUI对象(用B表示),则B的NGUI坐标为
2D坐标->2D坐标
比如现在需要在屏幕上随意点一个坐标,让某个NGUI对象(用B表示)移动到指的那个点,其中B的父节点为NGUI对象A,A的坐标为Vector.zero,则B的NGUI坐标为:
比如现在需要在一个用3D摄像机渲染的物体(用A表示)的相对坐标为(10,-5,91)的地方放置一个物体(用B表示),则B的世界坐标为
Vector3 screenPos = Camera.main.WroldToScreenPoint(A.transformPoint(new Vector3(10,-5,91))); Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos );
3D坐标->2D坐标
比如现在有一个用3D摄像机渲染的物体(用A表示),想在他的看起来的位置上方一个NGUI对象(用B表示),则B的NGUI坐标为
Vector3 screenPos = Camera.main.WorldToScreenPoint(A.transform.position); Vector3 nguiPos= NGUICamera.ScreenToWorldPoint(screenPos);
2D坐标->2D坐标
比如现在需要在屏幕上随意点一个坐标,让某个NGUI对象(用B表示)移动到指的那个点,其中B的父节点为NGUI对象A,A的坐标为Vector.zero,则B的NGUI坐标为:
Vector3 nguiPos = NGUICamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePositionb,y,0)); B.transform.localPosition = A.transform.InverseTransformPoint(nguiPos);
相关文章推荐
- unity图片打包
- unity5.X 中的全局光照技术详解(建议收藏)
- Unity学习笔记
- Unity鼠标设置
- Unity中使用Json解析字符串
- Unity 下载
- Unity3D——MonoBehaviour api函数 调用时序剖析(From 圣典)
- unity生成android release 版本的apk性能比较好
- unity set texture offset
- unity 场景的制作prefab 摆东西
- unity 2048 noplaymaker text
- unity playmaker player
- unity admob
- Unity3D游戏开发之游戏读/存档功能在Unity3D中的实现
- Unity Editor 编写unity插件类
- Unity Editor 编写unity插件类
- 【Unity】NGUI核心组件之UIPanel
- 【NGUI】Unity使用Resources加载NGUI的图片
- 基于Unity行为树设计与实现的尝试
- Unity游戏开发使用Assetbundle加载场景实战