What’s wrong with the second code? the two codes do the same, but in the second code, the script attached to the GameObject doesn’t play or dont work, in the first script all works correctly but when i have much weapons the script will be giant
// First Code
if(currentSecondaryWeapon == "M9") {
secondaryWeapons[0].SetActive (true);
secondaryWeapons[1].SetActive(false);
}
else if(currentSecondaryWeapon == "Glock") {
secondaryWeapons[0].SetActive (false);
secondaryWeapons[1].SetActive(true);
}
// Second Code
if(currentSecondaryWeapon == "M9") {
foreach(GameObject secondaryWeapon in secondaryWeapons) {
secondaryWeapon.SetActive (false);
}
secondaryWeapons[0].SetActive (true);
}
else if(currentSecondaryWeapon == "Glock") {
foreach(GameObject secondaryWeapon in secondaryWeapons) {
secondaryWeapon.SetActive (false);
}
secondaryWeapons[1].SetActive (true);
}