Regenerate health over time

I have this integer static var energyObj : int = 5; and then I have got another script, which subtracts one “energyObj” if you lose a level, then if you have zero “energyObj”, you cant play before they have regenerated atleas one. Now my problem is, I cant seem to find a way to regenerate every 30 minute, i can only find ways to do it each second with the Time.deltatime var but thats not how it is supposed to regenerate. Is there a way to make it regenerate every 30 minute instead of each second?

use a loop

var counter : float;

function Update(){
 counter += Time.deltaTime;
 if(counter > 30minutes){
  counter = 0.0; }

 //if energyObj should't be above 5
 if(energyObj > 5)
 energyObj = 5;

You can use a coroutine with an infinite loop inside which you have a yield WaitForSeconds(1800 / maxEnergy) and increase energyObj by 1. You can call this coroutine in your Start function and it will be ever active, it depends on your game logic.

For example (may be there’s few minor syntax oversight, I use C# usually):

function Regen() {
   var maxEnergy : int = 5;
   var seconds : float = 1800 / maxEnergy; // 1800 is 30 minutes in seconds
   while (true) {
       if (energyObj < maxEnergy)
       yield WaitForSeconds(seconds);