However, the trigger is not working. I have marked the ‘is trigger’ box on the collider of my object and my limit. I’ve added a rigidbody to both as well. I’m working with 3d objects. I’ve also assigned the tags to the objects.
I added the debug.log but nothing seems to be happening.
The problem is you keep moving the object in the same direction inside Update function no matter where the object is.
Once the OnTriggerEnter function fires, the object will move towards (-dirX, -dirY, 0) for only one frame and then continue to move towards (dirX, dirY, 0) afterwards (because of the Update function), so it looks like it doesn’t work. Instead of calling transform.Translate inside OnTriggerEnter, just change dirX and dirY and let the Update function move the object.