简体   繁体   English

Unity UI 文本位置

[英]Unity UI Text position

I'm trying to learn Unity UI element position.我正在尝试学习 Unity UI 元素的位置。 But when i am trying to get UI text position with this code Debug.Log (UI_Text.transform.position);但是当我尝试使用此代码Debug.Log (UI_Text.transform.position);获取 UI 文本位置时Debug.Log (UI_Text.transform.position); , i am getting high point like this (6846.1, 29931.3, 10.0) . ,我得到了这样的高点(6846.1, 29931.3, 10.0) In my code i attached UI text as Gameobject with UI_Text name.在我的代码中,我将UI 文本附加为带有UI_Text名称的Gameobject Also i can get UI element's screen and world point with this two code:我也可以用这两个代码获得 UI 元素的屏幕和世界点:

Debug.Log (Camera.main.WorldToScreen(UI_Text.transform.position));
Debug.Log (Camera.main.ScreenToWorld(UI_Text.transform.position));

This 2 codes working right, gives scene and world points and i understand these.这 2 个代码工作正常,给出了场景和世界点,我理解这些。 But i do not know how to work this code Debug.Log (UI_Text.transform.position);但我不知道如何处理这段代码Debug.Log (UI_Text.transform.position); and what is this position (6846.1, 29931.3, 10.0) .这个位置是什么(6846.1, 29931.3, 10.0) How can i get this position from camera like this Camera.main.Something ?我怎样才能从像这个Camera.main.Something这样的相机获得这个位置? This is my Canvas inspector And here is UI text inspector这是我的画布检查器这是UI 文本检查器

you can change RENDER MODE to space world - camera.您可以将渲染模式更改为太空世界 - 相机。 image1图片1

after this set main camera to RENDER CAMERA.之后将主摄像机设置为 RENDER CAMERA。 image2图像2

this mode perfect for 2d game .这种模式非常适合 2d 游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM