- Home /
switch weapon onDestroy
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. weapon 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 to get the weapon
the first questions answer wasnt working!. this is the problem i know that but i dont know a way to get the same results and it must be 1 not 0.
else if (gameObject.Destroy(gameObject); SelectWeapon(1);
the script function Start () { // Select the first weapon SelectWeapon(0); else if (gameObject.Destroy(gameObject); SelectWeapon(1); }
}
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);
}
}
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);
}
}
Answer by Aldwoni_legacy · May 10, 2011 at 03:31 PM
Don't make a new question when your first isn't been answered.