Reducing a value over time

Ok, read a few questions, haven’t managed to get anything to work.

I have a system set up so when someone leaves a building, their body temp should decrease over time, using a modifiable variable. Everything i try so far either leaves it not working at all, or defaulting to frames rather than seconds. I’m using js. Below is the relevant lines from my current code, with my last attempt at getting it to work.

var bodytemp : float = 20.0;
var heatloss : float = 0.1;
var playeroutside : boolean = false;

if (playeroutside){
		 InvokeRepeating("bodytempmody", 2, 20);
	}

function bodytempmody (){

bodytemp -= heatloss;
}

Any thing anyone can suggest is much appreiciated.

Maybe you could use Time.deltaTime? (Time passed since last frame). This should give you a steady decrease of 0.1 to bodytemp each second

Untested however so I could be wrong

 var bodytemp : float = 20.0;
    var heatloss : float = 0.1;
    var playeroutside : boolean = false;
    
    if(playeroutside){
    bodytemp -= heatloss*Time.deltaTime;
    }

Try this:

var bodytemp : float = 20.0;
var heatloss : float = 0.1;
var playeroutside : boolean = false;
var function_lock = false;

function Update(){
   if (playeroutside && !function_lock){
      function_lock = true;
      bodytempmody();
   }
}

function bodytempmody(){
   yield WaitForSeconds(2);
   bodytemp -= heatloss;
   function_lock = false;
}