How can i keep making the SendMessage repeat as long as the boolean is true

I have a kind of energy bar where when i collect enough i can instantiate an object, but i want the the energy to drain over time for as long as that object is alive.

I can make it reduce it once but struggling to make it repeat, pretty sure i’d be doing something in the if(orbAlive == true){ guiRef.SendMessage(“SetFocus”, spentAmount)); line i’ve tried a few things and still no success, so my question is how can i make the value of spentAmount be subtracted every second

var spentAmount : float = 1;
var particle:GameObject;
private var guiRef:GameObject;
private var orbAlive: boolean = false;


function FireAndReload (){
		
	if(GameObject.Find("__GameMaster").GetComponent(Score).focus >= 5){
		
	//Instantiate stuff in in here then setting the boolean true
				orbAlive = true;
	}
				if(orbAlive == true){
				guiRef.SendMessage("SetFocus", spentAmount));
                             }
					if(GameObject.Find("__GameMaster").GetComponent(Score).focus <= 0){
						orbAlive = false;
						Destroy(particle);
					}
	}
}

The direct answer would be to do this:

function FireAndReload(){
....
if(orbAlive == true){
 InvokeRepeating("EverySecond", 1.0, 1.0); //Calls EverySecond every second
}
...
}

function Update(){
{
 if(orbAlive == false)
 CancelInvoke("EverySecond"); //Stops EverySecond
}
...
}

function EverySecond(){
guiRef.SendMessage("SetFocus", spentAmount));
}

but i would recommend you to maybe let the script you send the message to handle the EverySecond part. Using SendMessage every second is not very performance-friendly.

Warning: This code is untested.

Hope it works for you.