How do I drag UI only on the Y-axis?

Every guide I look up just shows me how to drag and drop in an inventory system. If I could have some help or direction on how to drag a UI element on the Y-axis in Unity 2D it would be greatly appreciated.

You might have to be a bit more specific about what you’re looking for here. UI elements can be positioned in quite a few ways, and how you’d do it depends greatly on how the element is anchored and where its pivots are.

If the element is anchored vertically, you can adjust its position using the Pos Y attribute.

If it has a relative anchor for its vertical axis, you’d position its edges using the Top and Bottom fields.

How and why you’d use either setup depends greatly on what you want to do with the element, and how you want it to scale or move with a change of the canvas size. If you haven’t already, I strongly recommend reading the manual on the subject.

I’m trying to get player input with the event system to drag the UI, but nothing works.

Well what part isn't working? Are you receiving the user's mouse coordinates and drag state? Is the UI element moving at all? Are you getting any error messages?

It'd be a lot easier to help if you shared your code and some screenshots of how things are setup.

I have this

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class MenuUIMovement : MonoBehaviour, IPointerDownHandler, IPointerClickHandler,
    IPointerUpHandler, IPointerExitHandler, IPointerEnterHandler,
    IBeginDragHandler, IDragHandler, IEndDragHandler


    public void OnBeginDrag(PointerEventData eventData)
        Debug.Log("Drag Begin");

    public void OnDrag(PointerEventData eventData)


    public void OnEndDrag(PointerEventData eventData)
        Debug.Log("Drag Ended");

    public void OnPointerClick(PointerEventData eventData)
        Debug.Log("Clicked: " +;

    public void OnPointerDown(PointerEventData eventData)
        Debug.Log("Mouse Down: " +;

    public void OnPointerEnter(PointerEventData eventData)
        Debug.Log("Mouse Enter");

    public void OnPointerExit(PointerEventData eventData)
        Debug.Log("Mouse Exit");

    public void OnPointerUp(PointerEventData eventData)
        Debug.Log("Mouse Up");


The code above is my starting point, and it tells me what’s happening with the player’s mouse input in the console. No matter what code I add to this base code, it does not work. I can’t find any reference on how to use player input to drag anything. I will reread the Unity manual on this subject as you suggested today.

Do you have an EventSystem in your scene? Does your canvas have a GraphicsRaycaster component? Do you have any invisible UI elements overlapping your element that may be intercepting the mouse events?

Again, without being able to see what you're actually doing, it's hard to give you more specific help.

Yes I have an event system, and yes my canvas has a graphicsRaycaster component. No, I don’t have any overlapping or invisible UI. I have everything, I just can’t find any code to reference that will move a UI element in a script with player input and the event system. I can take pictures later today. Thank you for your help.

I can take a picture later, but for now, it is a ui image on a canvas. I want to learn how to move it down with the mouse.

Thank you for your help. I did learn a lot I was able to find a tutorial here: