2020-08-17【Unity】世界坐标转相机坐标,用GUI显示文字

一般用在ui上比较多。要让ui悬浮在物体上方,需要将物体坐标转换为ui坐标。
https://blog.csdn.net/Stephanie_1/article/details/78132070

            Vector3 canvasScale = Camera.main.WorldToViewportPoint(x.data.roomObject.transform.position);
            //Debug.Log(canvasScale);
            //var resolution = Screen.resolutions[0];
            //Debug.LogError(resolution.width + " " + resolution.height);

            GUI.Label(new Rect(2560 * canvasScale.x, 1440 * (1 - canvasScale.y), 400, 400), s);

https://blog.csdn.net/qq_41973169/article/details/108141097?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link

你可能感兴趣的:(2020-08-17【Unity】世界坐标转相机坐标,用GUI显示文字)