- Home /
OnTriggerEnter2D not working at all
Hi so what I have here is a Cube object (percentCollider) that has an isTrigger on its Box Collider. And the object that is going to move into it is also a Cube object (DrawingCircleCollider) that is being moved around by the mouse, has a Rigid Body. So that when I move the mouse it can trigger a count to go down in value. Problem is that it doesn't work at all. The first Debug doesn't even show up. I've been able to make something like this work many times but for some reason I'm lost on this.
Any help would be appreciated!
public GameObject drawingCircleCollider;
public Text percentageText;
public int count;
void Start()
{
count = 100;
SetCountText ();
}
void OnTriggerEnter2D (Collider2D percentCollider)
{
Debug.Log ("WORKING");
if (percentCollider.CompareTag ("DrawingCircleCollider"))
{
count = count - 1;
SetCountText ();
Debug.Log ("COUNT OK");
}
}
public void SetCountText()
{
percentageText.text = "" + count.ToString () + "%";
}
Hello, Have you used BoxCollider2D in unity ?
if you have 3D objects(with 3D collider and rigidbody) then you need to use OnTriggerEnter(Collider collider) method
if you have 2D objects (with 2d Collider and Rigidbody2D) then you need to use OnTriggerEnter2D(Collider2D collider)
Hope it will help you
Hey yeah so I have a BoxCollider2D on the trigger and I have a RigidBody2D on the object that would move through the trigger. Still doesn't work. The script is attached to the trigger object by the way.
Thanks for the reply
Answer by ILoveMyDada · Feb 06, 2018 at 10:50 AM
Never mind I got it to work by just doing away with 2D in general and just switched to 3D. That seemed to work fine.