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?
You are using
GetLocalCorners
which are relative to the center of your object.You can try using GetWorldCorners.