Why nothing happens if a Box Collider enters a Trigger?
I have 2 objects: a Box Collider (controllable with the arrow keys) and another Box Collider which is set on "Is Trigger".
The Trigger Box Collider has attached a script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class isWall : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Wall_Verifier")
Debug.Log("It's a wall :)");
}
}
In theory when the Box Collider (called "Wall_Verifier") enters this Trigger, the console should print "It's a Wall", but, in reality, nothing happens!
I even tried to put this piece of code inside the script attached to "Wall_Verifier", the result is the same as above.
Where's the error?
Answer by Frydie · Jun 04, 2017 at 12:29 PM
It was something that had to do with the rigidbodies, I attached to "Wall_Verifier" a Rigidbody2D and now it works
Answer by hoopos · Jun 03, 2017 at 03:00 PM
You say that the Box Collider is called "Wall_Verifier",but is it also tagged as "Wall_Verifier"?
O$$anonymous$$.Then check the colliders,they must be 2D colliders.
They're both 2D colliders
Wall_Verifier collider
The trigger collider