简体   繁体   English

如何在Unity的游戏视图中获取项目的坐标

[英]How to get the cordinates of an Item in Game view in Unity

I'm trying to make a slider in Unity, and I'm having a problem with getting the Cordinates of the Gameview or whatever this Window is:我正在尝试在 Unity 中制作一个 slider,但在获取 Gameview 的坐标或此 Window 是什么时遇到问题: Unity场景图片

to set the location of the light Bar in between the two moovable dots.将灯条的位置设置在两个可移动点之间。 When I try Using Transform.position it gives me its global position. I hope someone understands what I am asking, Thanks in Advance!当我尝试使用 Transform.position 时,它给了我它的全局 position。我希望有人能理解我的要求,在此先感谢!

The area you are pointing at is Canvas. By default it's location is (0;0;0) therefore meaning all elements' local positions to Canvas are same as global.您指向的区域是 Canvas。默认情况下它的位置是 (0;0;0) 因此意味着所有元素的本地位置到 Canvas 与全局相同。

To get control's local position you may use transform.localPosition().要获取控件的本地 position,您可以使用 transform.localPosition()。 Link with example: https://docs.unity3d.com/ScriptReference/Transform-localPosition.html示例链接: https://docs.unity3d.com/ScriptReference/Transform-localPosition.html

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

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