3 turn 2 2 turn 3

There is a perspective camera that illuminates 3D objects in the scene. NGUI uses its own independent orthogonal camera. The conversion steps are as follows: 


1. Convert world coordinates to screen coordinates using a perspective camera

Vector3 pos = Camera.main.WorldToScreenPoint(worldPos);

pos.z = 0f; //z must be 0.


2. Use UI camera to convert to NGUI world coordinates

Vector3 pos2 = UICamera.currentCamera.ScreenToWorldPoint(pos);


3. Assignment to NGUI control

temp.transform.position = pos2;  //temp is an NGUI control.

            //camera is different so it needs to be converted by screen coordinates

            //Finally converted to 3d world coordinates, because the object hanging points are different, and the world 3d does not need to be calculated again

            //z is 0 to prevent interference from 2 to 3


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324838875&siteId=291194637