Unity UGUI坐标转为3D世界坐标 世界左边转为UGUI坐标

承接ARVR项目开发: QQ 2118590660

UGUI坐标转为世界坐标

 

 

		
			Vector3 scr = RectTransformUtility.WorldToScreenPoint (canvas.worldCamera, obj.transform.position);
			scr.z = 0;
			scr.z = Mathf.Abs (Camera.main.transform.position.z - transform.position.z);
			currentObj.transform.position = Camera.main.ScreenToWorldPoint (scr);
			

 

 

 

 

世界坐标转为UGUI坐标

 


		Vector2 pos;
		RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Camera.main.WorldToScreenPoint(obj.transform.position), canvas.worldCamera, out pos);
		RectTransform rect =deleteBtn.transform.transform as RectTransform;
		rect.anchoredPosition = pos;

 

 

 

 

 

参考 http://tieba.baidu.com/p/4477632392

你可能感兴趣的:(Unity)