Hello. How can I have a static variable decrease at a set rate after a period of inactivity? Ex: A value increases when a player shoots an enemy. If the player has shot no enemies for 5 seconds, the value will start to decrease at a rate of 2 every 3 seconds. Thanks
Something like this -
var lastScoreTime : float;
var score : float;
var pointLossPerSecond : float = 0.67;
var penaltyTime : float = 0.5;
function Score( amnt : int ) {
score += amnt;
lastScoreTime = Time.time;
}
function Update() {
if ( Time.time - lastScoreTime > penaltyTime ) score -= Time.deltaTime * pointLossPerSecond;
score = Mathf.Max(0, score);
}
Humm, try something like this:
static var Score : int = 20;
static var KilledEnemy : boolean = false;
function Update()
{
if(KilledEnemy == false){
Invoke("Timer", 5);
}
}
function Timer()
{
Score =-2;
yield WaitForSeconds(3);
Score =-2;
return;
}
Hasn't been tested, in a hurry - sorry.