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