Trying to use the spacebar ONLY to cycle through 4 weapons.
The following script seems to be pretty straight forward but is stuck on SelectWeapon(0) at runtime. Yes, it's a tweeked version of the standard FPS tutorial script.
Any thoughts are appreciated.
function Start ()
{
SelectWeapon (0);
}
function Update ()
{
if (Input.GetButton ("Fire1"))
BroadcastMessage("Fire");
if (Input.GetKeyDown("space") && SelectWeapon == 0)
{
SelectWeapon (1);
}
else if(Input.GetKeyDown("space") && SelectWeapon == 1)
{
SelectWeapon (2);
}
else if (Input.GetKeyDown("space") && SelectWeapon == 2)
{
SelectWeapon (3);
}
else if (Input.GetKeyDown("space") && SelectWeapon == 3)
{
SelectWeapon (0);
}
}
function SelectWeapon (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);
}
}