用dedecms织梦做中英文网站,帝国cms 网站地图标签,民宿平台搜索量上涨,做外贸都做哪些网站好免费介绍1.WorldSpace(世界坐标系)当我们向场景中添加物体时#xff0c;他们都是以世界坐标系的方式的方式显示在场景中的通过transform.position可以得到它在世界中的坐标位置#xff0c;transform.position(Vector3)可以设置它在世界中的位置(c#不支持单独设置x y z)#xff1…介绍1.WorldSpace(世界坐标系)当我们向场景中添加物体时他们都是以世界坐标系的方式的方式显示在场景中的通过transform.position可以得到它在世界中的坐标位置transform.position(Vector3)可以设置它在世界中的位置(c#不支持单独设置x y z)2.ScreenSpace(屏幕坐标系)以像素为单位左下角是(00)右上角为(screen.width, screen.height)Z的位置是以相机的世界单位来衡量//及物体离相机远近注鼠标位置坐标属于屏幕坐标Input.mousePosition可以获得鼠标坐标手指触摸屏也为屏幕坐标Input.GetTouch(0).position可以获得单个手指的手机屏幕坐标说点题外话unity中Input.GetMouseButtonDown(0)代表按下鼠标左键Input.GetMouseButtonDown(1)代表鼠标右键Input.GetMouseButtonDown(2)代表滚轮中间。3.ViewPort(视口坐标)左下角为(0 0)右上角为(1 1)在一些画中画效果中常用到比如主视口为FPS然后右下角有一个小窗口为第三人称视图。4.绘制GUI界面的坐标系(自从有了新版UI之后这个也很少用到)这个坐标系与屏幕坐标系类似不同的是左上角为(00)右下角为(screen.width, screen.height)这样绘制起来更方便。5.桌面坐标系(系统坐标系)这个坐标系与屏幕坐标系类似不同的是该坐标系以桌面的左上角为(00)桌面右下角为桌面分辨率的宽和桌面分辨率的高用SetCursorPos设置鼠标坐标用GetCursorPos得到鼠标坐标。C#中命名空间 using System.Runtime.InteropServices;导入库 [DllImport(user32.dll)]函数原型 public static extern int SetCursorPos(int x, int y);public static extern bool GetCursorPos(ref int x, ref int y);******************************************************转换1.物体的世界坐标到屏幕坐标的转换C#1Camera.main.WorldToScreenPoint(cb.transform.position);//cb代表场景中的一个方块物体得到的vector3中的z为相机离cube物体的远近2.屏幕坐标转世界坐标C#1Vector3worldCamera.main.ScreenToWorldPoint(Input.mousePosition);//及鼠标单击位置距世界中心(000)点的距离3.屏幕坐标转视口坐标C#1Vector3viewCoorCamera.main.ScreenToViewportPoint(Input.mousePosition);//底层原理无非就是Input.mousePosition.x/Screen.width,Input.mousePosition.y/Screen.Height;4.视口坐标转屏幕坐标C#1Vector3screenCamera.main.ViewportToScreenPoint(newVector3(0.2f,0.3f,0));//注意视口左下角为(00)右上角为(11)5.视口坐标到世界坐标C#1Vector3wordCamera.main.ViewportToWorldPoint(newVector3(0.2f,0.3f,0));//注意当只改变一个z值时转化出的世界坐标的xy也会发生相应的变化6.屏幕坐标转射线C#123456789if(Input.GetMouseButtonDown(1)){RayrayCamera.main.ScreenPointToRay(Input.mousePosition);// 从鼠标位置发送射线RaycastHithit;if(Physics.Raycast(ray,outhit,100,1{Debug.Log(hit.collider.name);}}6.视口坐标转射线C#123456789if(Input.GetMouseButtonDown(1)){RayrayCamera.main.ViewportPointToRay(newVector3(0.5f,0.5f,0));// 从屏幕中央发送射线RaycastHithit;if(Physics.Raycast(ray,outhit,100,1{Debug.Log(hit.collider.name);}}最后编辑2017-12-05作者网虫虫分享是一种快乐分享是一种美德分享是一种幸福