Need help from a specialist

if i have got a function, and i want to be able to press GUI Buttons for playing/pausing/rewinding the function itself (it has a for loop). How am i supposed to do this so the buttons do not interfere with each other and end up launching mutliple instances of my function? any help is hghly appreciated

bio

It sounds like the simplest way is to, inside the for-loop, check for statements.

if(state=="play"){
  i++;
} else if (state=="rewind"){
  i--;
} else if (state=="pause"){
  break;
}

(Bear in mind that string comparison is slower than for instance checking booleans or an int, the example is just for simplicity.)
At pause you exit the loop. The state can be set from your GUI-buttons, as long as you initiate the variable outside any function. Would this work in your situation?

Also if your buttons should start coroutines, you could also stop any given coroutine before launching it again:

StopCoroutine("MyRoutine");
StartCoroutine("MyRoutine");

There’s also the possibility to wait for a coroutine to finish using:

yield StartCoroutine("MyRoutine");

It’s hard to tell what would be most suitable for your situation.