I want the newly instantiated game object (the name of the object is DragObjectCard) to follow the mouse, please help. I have tried multiple different methods but none worked. Is there any way to do this. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateObjectDrag : MonoBehaviour
{
public GameObject DragObjectCard;
public GameObject ObjectCard;
public GameObject target;
public Vector2 position;
public void OnMouseDown()
{
if (Input.GetButtonDown("Fire1"))
{
GameObject newDrag = Instantiate(DragObjectCard);
newDrag.transform.position = new Vector2(ObjectCard.transform.position.x, ObjectCard.transform.position.y);
}
}
}