I have a invisible box (trigger) that detects a specific type of object. It follows the player. I'm having a problem that I need it to not detect the red blocks through walls.
Use raycasting to see if there's an obstacle between the player and the object you're detecting: https://unity3d.com/learn/tutorials/topics/physics/raycasting
There is a player sphere and there are red blocks. I have a trigger that follows the player that detects red blocks and does raycasting to see if it's through walls but sometimes when you should activate it. It just won't activate.
You need to narrow down why that is happening. Use Debug.Log so you can see if the code is taking the path you imagine it is. Or you could post some code. There is still insufficient information. I will add that if a raycast will not detect a collider it is overlapping at the origin.