Weapon Switching

Hi jeff here again,I want to switch between more than 2 weapons , i already have the script for 3 or more but it doesn’t seem to work… I can only use 2 weapons …Anyone can help me? i’ll post my script here…

Thank You!

function Start () {
	// Select the first weapon
	SelectWeapon(0);
}

function Update () {
	// Did the user press fire?
	if (Input.GetButton ("Fire1"))
		BroadcastMessage("Fire");
	
	if (Input.GetKeyDown("1")) 
    {
        SelectWeapon(0);
    }
    else if (Input.GetKeyDown("2")) 
    {
        SelectWeapon(1);
    }
    else if (Input.GetKeyDown("3")) 
    {
        SelectWeapon(2);
    }
    else if (Input.GetKeyDown("4")) 
    {
        SelectWeapon(3);
    }


function SelectWeapon (index : int) {
	for (var i=0;i<transform.childCount;i++)	{
		// Activate the selected weapon
		if (i == index)
			transform.GetChild(i).gameObject.SetActiveRecursively(true);
		// Deactivate all other weapons
		else
			transform.GetChild(i).gameObject.SetActiveRecursively(false);
	}
}
function SelectWeapon (index : int) {
   for (var i=0;i<transform.childCount;i++)   {
      // Activate the selected weapon
      if (i == index)
         transform.GetChild(i).gameObject.SetActiveRecursively(true);
      // Deactivate all other weapons
      else
         transform.GetChild(i).gameObject.SetActiveRecursively(false);
   }
}

im not sure, but is there anything missing^^

i think the “{}” are missing in your if, else.

Ty mate it worked :wink: