Hello, I've got in trouble.

Hello guys, today I’ve installed Unity, since I’ve been thinking alot about 1 game and it would be pretty great to make it true, but… I’ve stucked. When I click play I can’t Drag that “item” how is called.
Here is my system which I’ve done in Visual studio
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;

public class ******* : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {

public void OnBeginDrag (PointerEventData eventData) {
Debug.Log(“OnBeginDrag”);
}

public void OnDrag(PointerEventData eventData) {
Debug.Log(“OnDrag”);

this.transform.position = eventData.position;

}

public void OnEndDrag(PointerEventData eventData) {
Debug.Log(“OnEndDrag”);
}

}

Can you tell me what I’ve done wrong? Or what should I add? Also I checked console and I there is none kind of error. The game is about card game, so yeah… I can’t drag and move card… I am also “new”, so I was wondering do you have any recommandation of tools which could help for beginner?

Thanks for helping me out of here.

You aren’t doing anything when it detects a drag. Make the item follow the cursor during OnDrag.

Also, use Code Tags to post code on the forum so it’s legible.

Sorry, I am confused now. What should I change to make the item follow the cursor during ondrag? :confused: i’m not enough smart for that :confused: i was trying different way too, but it hasn’t worked…

Well, I’ve been trying to do something similar to ChaoticMaker here. I’m also fairly new to Unity.I also have nearly the same code as him, we’re probably following the same video by quill18.

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

[RequireComponent(typeof(Image))]
public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{


    void Start()
    {
        Debug.Log("GameStart");
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        Debug.Log("OnBeginDrag");
    }
  
    public void OnDrag(PointerEventData eventData)
    {
      
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        Debug.Log("OnEndDrag");
    }
}

I attached this script to a UI image, parented to a panel, parented to a Canvas with an EventSystem in the scene. I also added a Canvas Group component to the image and have interactable and blocks raycasting enabled.

When I run the scene and attempt to drag and drop my image (which henceforth shall be called my card), I expect the console to have three logs - GameStart, OnBeginDrag and OnEndDrag. However, all I have is GameStart.

Edit : The Camera also has a 2-d Physics Raycaster attached.

Any help would be greatly appreciated, and will probably help ChaoticMaker as well as myself.

Thanks to some knowledgeable friends in Twitch Chat, the answer was found and I figured I would share here.

It seems that some time between 2015 and now, an update was released that changed the default setting on UI images. “Raycast Target” on the “Image ( Script)” is now disabled by default and needs to be enabled for the DragHandlers to function properly.

Koodo’s to kdo_92 and his twitch chat on Twitch.