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);
}
}
}