View and control script broken?

Hi all,

I have created this script to change between "seats" on a space craft. I had it working with just one "seat" (and its camera), and now after expanding the script to accommodate the other "seats" it no longer works for even the first seat.

Any pointers are greatly appreciated.

// seat position
var driver_seat : Transform;
var seat_1 : Transform;
var seat_2 : Transform;
var seat_3 : Transform;
var seat_4 : Transform;
var seat_5 : Transform;
var seat_6 : Transform;

// turret and ship cams
var ship_cam : Camera;
var cam1 : Camera;
var cam2 : Camera;
var cam3 : Camera;
var cam4 : Camera;
var cam5 : Camera;
var cam6 : Camera;

// timer
var timer : int = 30;

// ship
var ship : GameObject;

// active control vars
var state : int = -1;

// player position & cam
var play : Transform;
var player_cam : Camera;
function Update () 
{
    if ( Input.GetAxis ("e_key") && state == -1 && timer < 0)
    {
        timer = 30;

        if(Vector3.Distance (driver_seat.position, play.position ) < 1.5 )
        {
            state = 0;
            ship.BroadcastMessage ("Activate_Turret", 0);
        }

        //
        if(Vector3.Distance (seat_1.position, play.position ) < 3 )
        {
            state = 1;
            ship.BroadcastMessage ("Activate_Turret", 1);
            print ("a");
        }

        //
        if(Vector3.Distance (seat_2.position, play.position ) < 1.5 )
        {
            state = 2;
            ship.BroadcastMessage ("Activate_Turret", 2);
        }

        //
        if(Vector3.Distance (seat_3.position, play.position ) < 1.5 )
        {
            state = 3;
            ship.BroadcastMessage ("Activate_Turret", 3);
        }

        //
        if(Vector3.Distance (seat_4.position, play.position ) < 1.5 )
        {
            state = 4;
            ship.BroadcastMessage ("Activate_Turret", 4);
        }

        //
        if(Vector3.Distance (seat_5.position, play.position ) < 1.5 )
        {
            state = 5;
            ship.BroadcastMessage ("Activate_Turret", 5);
        }

        //
        if(Vector3.Distance (seat_6.position, play.position ) < 1.5 )
        {
            state = 6;
            ship.BroadcastMessage ("Activate_Turret", 6);
        }
    }

    // get out of turrets
    if ( Input.GetAxis ("e_key") && state > -1 && timer < 0)
    {
        state = -1;
        timer = 30;
        BroadcastMessage ("Activate_Turret", -1);
    }

    // switch cameras
    // player cam
    if (state == -1)
    {
        player_cam.GetComponent("Camera").active = true;
    }
    else
    {
        player_cam.GetComponent("Camera").active = false;
    }

    // cam 0
    if (ship_cam != null) 
    {
        if (state == 0)
        {
            ship_cam.GetComponent("Camera").active = true;
        }
        else
        {
            ship_cam.GetComponent("Camera").active = false;
        }
    }

    //cam 1
    if (state == 1)
    {
        cam1.GetComponent("Camera").active = true;
    }
    else
    {
        cam1.GetComponent("Camera").active = false;
    }

    // cam 2
    if (state == 2)
    {
        cam2.GetComponent("Camera").active = true;
    }
    else
    {
        cam2.GetComponent("Camera").active = true;
    }

    // cam 3
    if (state == 3)
    {
        cam3.GetComponent("Camera").active = true;
    }
    else
    {
        cam3.GetComponent("Camera").active = true;
    }

    // cam 4
    if (state == 4)
    {
        cam4.GetComponent("Camera").active = true;
    }
    else
    {
        cam4.GetComponent("Camera").active = true;
    }

    // cam 5
    if (state == 5)
    {
        cam5.GetComponent("Camera").active = true;
    }
    else
    {
        cam5.GetComponent("Camera").active = true;
    }

    // cam 6
    if (state == 6)
    {
        cam6.GetComponent("Camera").active = true;
    }
    else
    {
        cam6.GetComponent("Camera").active = true;
    }
}

I think you forgot to decrease your timer. And a copy&past error :D

Almost all cameras get set to "true" in both pathes. I think you want to turn them off in the else block ;)

And just a hint: why don't us use an array for your seats and cams? That script hurts inside :D

good luck.