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);
}
}