英文:
How to get details (Position ,Rotation, Scale) of the Game Object that is placed in real world as AR?
问题
当我使用Unity中的AR将游戏对象(例如:立方体)放置在现实世界中时,我想要以文本形式接收该游戏对象的详细信息,例如位置、旋转和在XYZ平面上的缩放,是否可能实现?
英文:
When I place a game object (e.g.: Cube) in the real world with the help of AR using Unity, I want to receive detail of that game object like the position, rotation and scale in xyz plane separately. Will it be possible to get it in text form?
答案1
得分: 1
最简单的方法是分别获取位置、旋转和缩放,代码如下:
Vector3 worldPosition = this.transform.position;
string worldPositionStr = worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z;
假设该脚本附加到相关对象上。要获取旋转,请使用this.transform.eulerAngles
而不是this.transform.position
,对于缩放,请使用this.transform.lossyScale
(查看每个字段的文档以更好地理解它们)。
但请记住,这些值是在当前AR会话的空间中。因此,这些值取决于您启动AR会话的位置,并且可能在每次重新启动会话时发生变化。
英文:
The easiest way to get position, rotation and scale separately would be like this:
Vector3 worldPosition = this.transform.position;
string worldPositionStr = worldPosition.x + ", " + worldPosition.y + ", " + worldPosition.z;
assuming the script is attached to the object in question.
For rotation use this.transform.eulerAngles
instead of this.transform.position
and this.transform.lossyScale
for scale (have a look at the documentation of each of those fields to better understand them).
You should keep in mind though that these values are in the space of the current AR session. So these values depend on where you start the AR session and might change each time you restart your session.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论