Swaping to a camera attached to another object

Looking at other scripts this one should work but it will not change the "state" variable.

I have manually changed this variable in game and the script switches cameras as it should, it just wont do it when I am pushing "e_key"

It shouldn't be a problem as I have doors using the same detection system and they work!

Would be great if anyone could give me a few pointers!

here is the code:

var player_cam : Camera;
var cam : Camera;

var state : int = 0;

function Update () 

{

    var hit : RaycastHit;

//find forward then test for x meters in front of position
if (Physics.Raycast (transform.position, transform.forward, hit, 2))    
{
    if(hit.collider.gameObject.tag=="Player" && Input.GetAxis ("e_key") )
    {
        if (state == 0)
        {
            state = 1;
        }
        if (state == 1)
        {
            state = 0;
        }   
    }
}

if (state == 1)
{
    player_cam.GetComponent("Camera").active = false;
    cam.GetComponent("Camera").active = true;
}
if (state == 0)
{
    player_cam.GetComponent("Camera").active = true;
    cam.GetComponent("Camera").active = false;
}

}

   if (state == 0)
    {
        state = 1;
    }
    if (state == 1)
    {
        state = 0;
    } 

You set state = 1, then test if state == 1. It always will. You need an 'else' there instead, or just

state = !state; or state = 1-state;

I would use a boolean instead.

var camSwitch : boolean = true;

function Update ()
{
  var hit : RaycastHit;

if (Physics.Raycast (transform.position, transform.forward, hit, 2))    
{
 if(hit.collider.gameObject.tag=="Player" && Input.GetAxis ("e_key") )
{
camSwitch = !camSwitch;

player_cam.GetComponent("Camera").active = camSwitch;
    cam.GetComponent("Camera").active = !camSwitch;
}
}

}

Also, since you're going to be accessing the other camera often (I presume) you might as well store it as a variable.

var player_cam : Camera;

//Then you can just write

player_cam.active = camSwitch.

You can just drag the camera into the player_cam variable in the inspector.