hey guys whats wrong with this script my script doesnt work i wanna make it so that when my 1 weapon gets destroyed by a damage reciever if its destroyed wapon 2 becomes 1 so weapon 2 is now weapon 1 i want the script to automaticaly go to the new 1 weapon so i dont have to push 6 again
function Start () {
// Select the first weapon
SelectWeapon(0);
}
function Update () {
// Did the user press fire?
if (Input.GetButton ("Fire1"))
BroadcastMessage("Fire");
if (Input.GetKeyDown("5")) {
SelectWeapon(0);
}
if (Input.GetKeyDown("6")) {
SelectWeapon(1);
}
else if (gameObject.Destroy(gameObject);
SelectWeapon(1);
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
// Activate the selected weapon
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
// Deactivate all other weapons
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}