question about invisible walls

so i created some invisible walls around parts of my game, but what annoys me is that rockets and stuff explode when it hits the wall. is there anyway that i can make it so only if a game object has a variable on it then it cant pass through, like:

if(cantGoThroughWall){

//some script here to make it not go through wall

}

or is there another way that i just dont know about?

Maybe there's a simpler way. Have you tried Physics.IgnoreCollision?

It even has an example exactly about bullets:

// Instantiate a bullet and make it ignore collisions with this object.
var bulletPrefab : Transform;
function Start () {
    var bullet = Instantiate (bulletPrefab);
    Physics.IgnoreCollision(bullet.collider, collider);
}

If you look in the Scripting Reference there is Physics.IgnoreCollision or something similar that will do just that.