Collider not working properly
I was creating a game where you drag a object from one side to the other using mouse
I made it working well until I wanted to destroy it if the object is not the one it needs to go to
I found out that it registers pointer that has collider first, and as its not right object, it destroy object that I dragged. I found out by testing with Debug.Log and it destroys it before it sets it, which is weird
How can I change the order of colliders object is detecting?
This is in my OnTriggerStay2D function
if (Input.GetMouseButtonUp(0))
{
if (col.tag == "Position")
{
if (col.GetComponent<ImePass>().NameReturn== GetComponent<SpriteRenderer>().sprite.name)
{
this.transform.parent = col.transform;
SetIt();
Debug.Log("Set it");
}
else if (GetComponent<Collider2D>().enabled)
Destroy(gameObject);
}
else if (col.tag != "Position" && GetComponent<Collider2D>().enabled && this.transform.parent.tag != "Position")
{
Destroy(gameObject);
Debug.Log("Destroy it cause its no position");
}
I did so much in if because I wanted to secure it and I tried with many things until I didn't use the debug log and saw that it first detects the mouse collider
I also disable collider if it gets to the position, that's inside SetIt() function