So my idea is I got a card and a delete button and I wanted to make the card diminish in size if its hovering over the delete button and once its dropped the card gets deleted.
From what I searched I need to use OnCollisionEnter2D but I still haven't found a way
This is the script I'm using to drag the card and I tried just doing the if its hovering gets deleted instantly part to test but its not working. I have defined the OnCollisionEnter2D function but I don't know how to call it inside the void Update().
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragDrop : MonoBehaviour
{
private bool isDragging;
private int hovering = 0;
private Vector3 startPos;
private void OnCollisionEnter2D(Collider hit)
{
if (hit.transform.gameObject.name == "deleteButton")
{
Destroy(this);
}
}
private void Start()
{
startPos = transform.position;
}
public void OnMouseDown()
{
isDragging = true;
}
public void OnMouseUp()
{
isDragging = false;
}
void Update()
{
if (isDragging)
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
transform.Translate(mousePosition);
}
else
{
transform.position = startPos;
}
}
}
Also both my objects already have hitbox's.
