Cycle weapons with only ONE key press (spacebar)

Trying to use the spacebar ONLY to cycle through 4 weapons.

The following script seems to be pretty straight forward but is stuck on SelectWeapon(0) at runtime. Yes, it's a tweeked version of the standard FPS tutorial script.

Any thoughts are appreciated.

 function Start () 
{
    SelectWeapon (0);
}

function Update () 
{

    if (Input.GetButton ("Fire1"))
        BroadcastMessage("Fire");

    if (Input.GetKeyDown("space") && SelectWeapon == 0) 
    {
        SelectWeapon (1);
    }
    else if(Input.GetKeyDown("space") && SelectWeapon == 1) 
    {
        SelectWeapon (2);
    }
    else if (Input.GetKeyDown("space") && SelectWeapon == 2) 
    {
        SelectWeapon (3);
    }
    else if (Input.GetKeyDown("space") && SelectWeapon == 3) 
    {
        SelectWeapon (0);
    }
}

function SelectWeapon (index : int) 
{
    for (var i=0;i<transform.childCount;i++)    
    {
        if (i == index)
            transform.GetChild(i).gameObject.SetActiveRecursively(true);
        else
            transform.GetChild(i).gameObject.SetActiveRecursively(false);
    }
}

this will work :)

private var selectedWeapon : int = 0;
    function Start () 
    {
        SelectWeapon (0);
    }

    function Update () 
    {

        if (Input.GetButton ("Fire1"))
            BroadcastMessage("Fire");

        if (Input.GetKeyDown("space")) 
        {
            selectedWeapon++;
            if(selectedWeapon == transform.childCount){
            selectedWeapon = 0;
            }
            SelectWeapon (selectedWeapon);

        }
     }

    function SelectWeapon (index : int) 
    {
        for (var i=0;i<transform.childCount;i++)    
        {
            if (i == index){
                transform.GetChild(i).gameObject.SetActiveRecursively(true);
            }
            else{
                transform.GetChild(i).gameObject.SetActiveRecursively(false);
            }
        }
    }

hope this works! :D

hello Guyss!!. I copy the same script in my game, it works well but the shooting, switching, weapon realoding is very fast like 100times of normal working. when i check weapons individually then they work well. i think your script has need of ‘Time.deltaTime’ function… I m a noob in programming , I don’t know where it will be put… in the script …or any other solution.Anybody help me to fix this problem. i m waiting for your answer… and Thanx in advance… sorry for the weak grammar.