I have four named variables:
float smoothPlusError = smoothAngle + angleError;
float smoothMinusError = smoothAngle - angleError;
float smoothMinus90 = smoothAngle - 90;
float smoothPlus90 = smoothAngle + 90;
I need to check if each of these variables is above or below a certain threshold and then adjust accordingly. To avoid repeating the same code four times, I am trying to do this in a loop as follows:
float[] angles = { smoothPlusError, smoothMinusError, smoothMinus90, smoothPlus90 };
for (int i = 0; i < angles.Length; i++)
{
if (angles[i] > 360)
angles[i] -= 360;
else if (angles[i] < 0)
angles[i] += 360;
}
The problem with this approach is that the array creates copies of the named variables and updating the values in the array does not update the original named variables.
Please advise how I can pass named variables to an array and update their original values?
smoothPlusError = angles[0];after the loop, though a method you apply to each would be a better idea.ref.