Mathf.PingPong Wrong?

Hi there, I’m trying to use Mathf.Pingpong to limit the min and max of a number (currentTargetIndex) and pingpong it between 0 and a MAX value (3):

currentTargetIndex++;

currentTargetIndex = (int)Mathf.PingPong (currentTargetIndex, 3);

So I’m after this: 0, 1, 2, 3, 2, 1, 0, 1, 2 etc etc
I’m getting the impression that this function isn’t designed to achieve what I’m after - or perhaps I"m just not using it correctly. Can anyone advise me? Any help, much appreciated!

It can’t work the way you’re using it, because you’re assigning the return value of PingPong back to the variable you’re passing in. PingPong is a static function with no memory of what it did the last time you called it. Use it like someOtherVariable = (int)Mathf.PingPong (currentTargetIndex++, 3); then someOtherVariable will go through the 0, 1, 2, 3, 2, 1, 0, etc. sequence.