unity recttransform.getLocalcorners(vector3 [] fourcornerSarray)结果不变为对象; s位置改变

发布于 2025-01-22 09:59:14 字数 748 浏览 5 评论 0原文

我的兄弟姐妹来自另一个母亲:)

我正在尝试使用Unity实现滑动菜单,就像智能​​手机上的应用菜单一样。我想获得当前角的本地位置值,因此我可以将它们用作参考来做一些事情。但是,当我拖动对象时,角落的价值似乎保持固定,这对我来说看起来很奇怪,因为该对象的相对位置(本地位置)肯定会更改,我不知道为什么角落的位置位置可以一直保持不变。

public class pageSwiper: MonoBehaviour, IDragHandler
{
  private Vector3 panelLocation;
  void start() {panelLocation = transform.position;}
  public void OnDrag(PointerEventData data)
  {
    float difference = data.pressPosiiton.x - data.position.x;
    transform.position = panelLocation - new Vector3(difference,0,0);
    Vector3[] corners = new Vector3[4];
    GetComponent<RectTransform>().GetLocalCorners(corners);
    Debug.Log(corners[0].x)
    Debug.log(corners[3].x)
  }
}

当我使用指针(鼠标)拖动对象时,调试的日志值始终相同。他们应该随着对象的移动而改变,不是吗?

my brothers and sisters from another mother : )

I'm trying using unity to implement a swipe menu, which is like the apps menu on a smart phone. I want to get the current corner's local location value, so I can use them as a reference to do some stuff. However, while I'm dragging the object, the corners' value seems remain fixed, which looks weird to me, since the object's relative position (local position) to its parent is definitely changed, I don't know why the corners' location position can all the way just stay the same.

public class pageSwiper: MonoBehaviour, IDragHandler
{
  private Vector3 panelLocation;
  void start() {panelLocation = transform.position;}
  public void OnDrag(PointerEventData data)
  {
    float difference = data.pressPosiiton.x - data.position.x;
    transform.position = panelLocation - new Vector3(difference,0,0);
    Vector3[] corners = new Vector3[4];
    GetComponent<RectTransform>().GetLocalCorners(corners);
    Debug.Log(corners[0].x)
    Debug.log(corners[3].x)
  }
}

while I using using pointer (mouse) drag the object, the Debug's log value always be the same. Should they change as the object moving, shouldn't they?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久夏青 2025-01-29 09:59:14

您正在使用GetLocalcorners,这些>与对象的中心相对。

您可以尝试使用 getWorldCorners

You are using GetLocalCorners which are relative to the center of your object.

You can try using GetWorldCorners.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文