在统一中,我试图获取我的游戏对象正在使用的 Sprite 的枢轴点。
我更改了 Sprite 的枢轴点,以便在将游戏对象(我们称之为 A)放置在游戏中时变得容易。现在,当我尝试在 A 的变换处生成另一个对象时,新的游戏对象(我知道它很热)会在 A 的左上角生成。我需要以某种方式计算在世界坐标中使用的 Sprite A 的中心。
我尝试过这个:
Debug.Log(tempGameObj.GetComponent<SpriteRenderer>().sprite.pivot);
但这产生的结果为 (-80,0,400),而枢轴点为 (-0.25, 1.25)。
如何计算中心?
最佳答案
您正在寻找的是 ScreenToWorldPoint 方法
Vector3 center = Camera.main.ScreenToWorldPoint(tempGameObj.GetComponent<SpriteRenderer>().sprite.pivot);
这是文档,以备您需要时使用 https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html
关于c# - 团结 : How to get the pivot of a game object's sprite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42601187/