how to activate OnBeginDrag?

I have a game object on hierarchy and a script attached to game object.
I couldnt reach the lines in function OnBeginDrag.
What am I possibly doing incomplete?

#pragma strict
import UnityEngine.EventSystems;
var itemDragged : GameObject;
var startPosition : Vector2;

function Start () {
   
}

function Update () {
   
    }


class dirag extends MonoBehaviour implements IBeginDragHandler, 
IDragHandler, 
IEndDragHandler
{
   
    function OnBeginDrag (eventData :PointerEventData)
    {
        itemDragged=gameObject;
        startPosition = transform.position;
        Debug.Log (gameObject.name + " " + startPosition);
    }
   
    function OnDrag (eventData :PointerEventData)
    {
        transform.position= Input.mousePosition;
    }
    function OnEndDrag (eventData :PointerEventData)
    {
        itemDragged=null;
        transform.position = startPosition;
    }
}

I have added a canvas and a button. It solved the problem.

Problem was probably no event system in the scene

there is an event system in the scene.
now i can reach all the functions but while i am dragging the object is not visible.

Add a canvasGroup component to your GameObject and in your script add :
to onBeginDrag:
GetComponent().blocksRaycasts = false;

to onEndDrag:
GetComponent().blocksRaycasts = true;

1 Like