Checking variable each frame to increase another variable every few seconds

I'm having issues getting one variable to update in response to the value of another variable.

Eg

Function Update () {
while (X > 0.9) {
Y --;
yield WaitForSeconds(2);
}
}

My problem is that I need to be checking X every frame, but waiting a couple of seconds before reducing Y. Obviously I can't have this in the update function due to the yield.

Invoke repeating wont work because X fluctuates based on actions the player takes.

The logic of the code is simple enough, but I've got no idea where I should be placing it so I don't end up in an infinite loop, or having the code execute instantly.

Use a time stamp instead:

var lastUpdate : float = 0.0;

function Update(){
   if(x>0.9 && Time.time-lastUpdate > 2){
      lastUpdate = Time.time;
      y--;
   }
}