VirtualJoystick.OnBeginDrag C# (CSharp) Method

OnBeginDrag() public method

public OnBeginDrag ( PointerEventData eventData ) : void
eventData UnityEngine.EventSystems.PointerEventData
return void
    public void OnBeginDrag(PointerEventData eventData)
    {
        // Make the thumb visible
        thumb.gameObject.SetActive(true);

        // Figure out where in world-space the drag started
        Vector3 worldPoint = new Vector3();
        RectTransformUtility.ScreenPointToWorldPointInRectangle(
            this.transform as RectTransform,
            eventData.position,
            eventData.enterEventCamera,
            out worldPoint);

        // Place the joystick at that point
        this.GetComponent<RectTransform>().position = worldPoint;

        // Ensure that the thumb is in its original location,
        // relative to the joystick
        thumb.localPosition = originalThumbPosition;
    }