Search Unity

[Solved] Framing a dragged GameObject

Discussion in 'UGUI & TextMesh Pro' started by jeffrey08, Dec 3, 2015.

  1. jeffrey08

    jeffrey08

    Joined:
    Nov 4, 2015
    Posts:
    6
    Hiya! :)

    I've build a drag and drop scene within a canvas element. I'm using IBeginDragHandler, IDragHandler, IEndDragHandler to handle the dragging events.

    I'm now using Input.mousePosition to move the position of the GameObject, but I'd like to only allow dragging in a certain frame. What I'm trying to do, is calculate the top/bottom side position of the containing element to limit the dragging in both directions. But I can't seem to figure out how I can use the parent.position.y and parent.GetComponent<RectTransform>().sizeDelta.y for calculations because they work on different levels.

    Is it possible to translate/transform the sizeDelta values to something I can use with calculating values from the position property? Or am I doing something completely wrong?

    Kind regards,

    Jeffrey
     
  2. jeffrey08

    jeffrey08

    Joined:
    Nov 4, 2015
    Posts:
    6
    Hiya,

    I've finally managed to solve it. Instead of using the sizeDelta values directly, I've had to recalculate them using the lossyScale value.

    Kind regards,

    Jeffrey