Weapon Switching Help

Hey im making a fps and i have all of my weapons and i have an in game pause menu to where you can buy weapons in a store. Im new to using child/parenting functions so im not sure on where to start with my coding. What i am trying to do is when a var is true it selects a certain child of the weapons game object and deselects the other when you press either 1 or 2, 1 being the primary weapon and the 2 being the secondary. Im trying to use this code but its not working how i want it to.

static var beretta = true;
static var deagle = false;
static var revolver = false;
static var m3 = false;
static var mp5 = false;
static var mp7 = true;
static var spaz = false;
static var trench = false;
static var toyshotgun = false;
var weapon : int;






function Start () 
{
	weapon = 0;
}

function Update () 
{
	
	if (Input.GetKeyDown("1")) 
	{
		if (m3)
		weapon = 1;
		
		if (mp5)
		weapon = 2;
		
		if (mp7)
		weapon = 3;
		
		if (spaz)
		weapon = 4;
		
		if (trench)
		weapon = 5;
		
		if (toyshotgun)
		weapon = 6;		
		
	}
	if (Input.GetKeyDown("2")) 
	{
		if (beretta)
		weapon = 0;//
		
		if (deagle)
		weapon = 7;
		
		if (revolver)
		weapon = 8;	
		
	}
}

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

is every weapon a child of the player, even ones they dont own? thats wierd. That is by the way what your code assumes.

for (var i=0;i<transform.childCount;i++) 

if they own 1 weapon the childcount might only be equal to 1. meaning that for loop will stop after the first thing.

change the code up

if(m3)
getcomponent<M3>();
//do what you want with the M3
if(berreta)
getcomponent<berreta>();
//do what you want with the berreta

each gun should have a script
each script should be the name of the gun

your probably thinking, but i want to call fire on all these weapons but have fire do different things depending on the weapon. That means you want a base class called weapon and then subclasses that inherit from it and override the base methods.

for example

class weapon()
{
public
bool fire();

}

bool weapon.fire(){

//do nothing now, your just creating a base so you can override later
return true;
}

class weapon::M3()
{
public
bool fire();
}

bool weapon::M3 fire()
{
fire as is appropriate for an M3
}

you do that for each weapon

now it is both a weapon and an M3 (polymorphism)

now you can create a weapon and call fire and it will do different things depending on the type of weapon it is.