var using time.time not resetting?

so in my code i have a variable that equals Time.time that only runs when a boolean is true, and i have it set to 0 if that boolean is false. However, when i turn that boolean back on the timer just returns to how it was before. Does anybody know how to fix this?

CODE:

var maximumDistance : float = 5;
var storerobbing : boolean = false;
var player : Transform;
var myTransform : Transform;
var minimumRobbingTime : float = 5;
var currentRobbingTime : float;
var robbed : boolean = false;

function Start () {

}

function Update () {

///
var distance = Vector3.Distance(player.position, myTransform.position);//figure out distance from self to player
if (distance <= maximumDistance && Input.GetButton ("action")){storerobbing = true;} // set storerobbing boolean to true if player is within maximumDistance 
///
if (storerobbing == true){ /// when storerobbing is true
currentRobbingTime = Time.time; //set the currentrobbingtime to Time.time
if (currentRobbingTime >= minimumRobbingTime){ // when currentrobbingtime is more than the minimum robbed is true
robbed = true;
} 

}
if (distance > maximumDistance){ storerobbing = false;
currentRobbingTime = 0;
}
}

change

currentRobbingTime = Time.time;

for

currentRobbingTime += Time.DeltaTime;

to track the “seconds”(update difference time)

Another way (though i am unable to test atm) to do this:

var maximumDistance : float = 5;
var storerobbing : boolean = false;
var player : Transform;
var myTransform : Transform;
var minimumRobbingTime : float = 5;
private var robbingTimeStart : float;
var currentRobbingTime : float;
var robbed : boolean = false;

function Update () {
	var distance = Vector3.Distance(player.position, myTransform.position);
	if (distance <= maximumDistance && Input.GetButton ("action") && !storerobbing){
		robbingTimeStart = Time.time;
		storerobbing = true;
	}

	if (storerobbing == true){
		currentRobbingTime = Time.time - robbingTimeStart;
		if (currentRobbingTime >= minimumRobbingTime){
			robbed = true;
		}
	}

	if (distance > maximumDistance){
		storerobbing = false;
	}
}

basically you grab the time that you started robbing, and minus that from the current time.

Scribe