unity recttransform.getLocalcorners(vector3 [] fourcornerSarray)结果不变为对象; s位置改变
我的兄弟姐妹来自另一个母亲:)
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用
GetLocalcorners
,这些>与对象的中心相对。您可以尝试使用 getWorldCorners 。
You are using
GetLocalCorners
which are relative to the center of your object.You can try using GetWorldCorners.