I have two tanks that both share a health script, and each tank is differentiated by a public variable. My issue is that when one tank health reaches 0, the onDeath section of the script will play, but only for that tank. There is important code that affects both tanks in the onDeath section, so I would like to be able to make the onDeath section play for both tanks when one dies. The current code looks something like this:
if (tankhealth >= 0) {
onDeath ();
}
With the code like this currently only the tank that has 0 health will play the onDeath section, but I would like the code to look something like this:
if (tankhealth >= 0) {
for (i = 0; i =2; i++) {
playernumber[i]
onDeath ();
}
}
but im not sure how to connect the two, and any way that i try to do this i get an error saying that the brackets arent allowed. Any way to connect this and make it work properly?
for (i = 0; i =2; i++)should befor (int i = 0; i < 2; i++)for a start.for (i = 0; i < playernumber.Length; i++)as @Ben says below is better still, avoiding "magic numbers" and making the intent clearer.tankhealthanintorfloat?