Health Regeneration

I have a damage receiver script and in it, I wrote a script to regenerate health:

#pragma strict

var hitPoints = 100.0;
var regen = 10; 
var detonationDelay = 0.0; 
var explosion : GameObject; 
var deadReplacement : Rigidbody;

function Update() {
    if(hitPoints <= 100) {
        hitPoints += regen * Time.deltaTime;
    }
}

The function update of course being the regeneration part. Well it’s not working. Here’s the whole script:

#pragma strict

var hitPoints = 100.0;
var regen = 10; 
var detonationDelay = 0.0; 
var explosion : GameObject; 
var deadReplacement : Rigidbody;

function Update() {
    if(hitPoints <= 100) {
        hitPoints += regen * Time.deltaTime;
    }
}

function ApplyDamage (damage : float) { 

hitPoints -= damage;
if (hitPoints <= 0.0) {
   
    var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
    if (emitter)
        emitter.emit = true;

    Invoke("DelayedDetonate", detonationDelay);
}
}

function DelayedDetonate () { BroadcastMessage ("Detonate"); }

function Detonate () {
	 
if (explosion)
    Instantiate (explosion, transform.position, transform.rotation);


if (deadReplacement) {
    var dead : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);

    
    dead.rigidbody.velocity = rigidbody.velocity;
    dead.angularVelocity = rigidbody.angularVelocity;
}


var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
if (emitter) {
    emitter.emit = false;
    emitter.transform.parent = null;
}
Destroy (gameObject);
}

I’m not sure why it’s not working. The regen should be adding to it every second by ten, but, nothing is happening. Why is this?

This is how I calculate regeneration. This uses 3 variables (all floats) but only 1 is changed so it really doesn’t impact performance. Also, I pair this with a death check formatted very similar that uses a <= 0 check in the same IF so that I don’t get regen/death check conflicts.

if ( structuralIntegrity < maxStructuralIntegrity ) {

    // Death Check goes here with a return(); to prevent further regen
  	structuralIntegrity += integrityRegen * Time.deltaTime;

}

Hope this helps!

Okay, since the question has been answered by myself (look at the comments of the question) I’m just posting this to say it’s correct. You are free to use the script as you like.