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

2020-08-17  本文已影响0人  持刀的要迟到了

一般用在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);
上一篇下一篇

猜你喜欢

热点阅读