首页 > 代码库 > 将世界坐标转成NGUI坐标

将世界坐标转成NGUI坐标

将世界坐标转成NGUI坐标,这个中间需要一个屏幕坐标,可参考如下代码:


/// <summary>
/// 将世界坐标转成UI坐标
/// </summary>
/// <param name="wordPos">Word position.</param>
public Vector3 wordPos_to_uiPos(Vector3 wordPos)
{
	Vector3 screenPos = Camera.main.WorldToScreenPoint (wordPos);
	screenPos = new Vector3 (screenPos.x, screenPos.y, 0f);
	Vector3 uiPos = uiCamera.ScreenToWorldPoint (screenPos);
	uiPos = uiCamera.transform.InverseTransformPoint (uiPos);
	return uiPos;
}


将世界坐标转成NGUI坐标