How to change a variable used in a loop for the outside ?

Hello,

I’ve made a coroutine which applies a buff to a player.

It works like this :

Applying Buff :

stoptime=Time.time+buffDuration;
StartCoroutine("BuffAttack");

Coroutine :

function BuffAttack();
    attack=2;
    while (Time.time<stoptime){
    	yield WaitForSeconds(0.1f);
    }
    attack=1;

I want to be able to extend the duration of the buff while it is applied. I use for this the following :

Refreshing Buff :

stoptime=Time.time+duration;

However, the stoptime in the while function is always the same.
How can I deal with this ? Thanks a lot.

check out this link

change variable in coroutine

kurt dekker posted a solution there