My script is not functioning correctly please help

in my unity game i put 3 childs under the camera of the first person im trying to select each one sepretly by selecting the key funtions 1,2, or 3. ive been messing with this for like an hour.

function Start()
 {
 	switchWeapon(0);
 }
 
function Update()
 {
 	if(input.GetKeyDown("1"))
 	{
 		switchWeapon (0);
 	}
 	else if(input.GetKeyDown("2"))
 	{
 		switchWeapon (1);
 	}
 	else if(input.GetKeyDown("3"))
 	{
 		switchWeapon (2);
 	}
 }
 
 function switchWeapon(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);
  	}

 
 }

Please help me! why isnt this working :face_with_spiral_eyes:

Hi, you almost had it, you have to watch the case of words like Transform, look at it in the for loop line, you have a capitol T in transform, should be lowercase.

I went ahead and put the code together for you again, one thing i like to do is cache my transform, its faster and helps avoid stuff like Transform vs transform, or GameObject vs. gameObject.

#pragma strict

private var tfm : Transform;

function Start () {
	// cache transform, it's faster
	tfm = transform;
}

function Update () {
	if (Input.GetKeyUp(KeyCode.Alpha1))
	{
		SwitchWeapon(0);
	}
	
	if (Input.GetKeyUp(KeyCode.Alpha2))
	{
		SwitchWeapon(1);
	}
	
	if (Input.GetKeyUp(KeyCode.Alpha3))
	{
		SwitchWeapon(2);
	}
}

function SwitchWeapon(weaponIndex : int)
{
	// loop thorugh, until we match the index of the weapon we want to turn on, 
	// if we don't match, turn the weapon off
	for (var i : int = 0; i < tfm.childCount; i++)
	{
		if (weaponIndex == i)
		{
			tfm.GetChild(i).gameObject.SetActiveRecursively(true);
		}
		else
		{
			tfm.GetChild(i).gameObject.SetActiveRecursively(false);
		}
	}
}

Hope this helps you out.

-Raiden