- Home /
Question by
jokerjosh15 · Mar 17, 2013 at 02:04 PM ·
javascript
Need help with WeaponSwitch Script
Thank you so much for your help in advance... I'm pretty new to unity so ya..
heres my script:
function Start()
{
SwitchWeapon
}
function Update()
{
if(Input.GetKeyDown("1"))
{
SwitchWeapon(0);
}
else if(Input.GetKeyDown("2"))
{
SwitchWeapon(1);
}
else if(Input.GetKeyDown("3"))
{
SwitchWeapon(2);
}
}
funtion; 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);}
}
}
Comment
are you using Unity4?
setActiveRecursively does not exist anymore. read the doco on SetActive() and so on.
note that at line 3 it is SwitchWeapon() you forgot the () brackets
as a general tule, do not use else if, if you're a beginner. make your code like this:
if ( Input.Get$$anonymous$$eyDown("3") )
{
SwitchWeapon(2);
return;
}
note the return;
copy and paste that three times, for your three possibilities.