- Home /
Bring down the value with time
Hi guys Hi guys I'm looking for a way to make sure that at some time the variable "Life" comes out of one point. In this way the variable goes down much faster because of course it sees the interval of one second. How can I fix this concept?
Thank you
if ((TimeScoreHours==16)&&(TimescoreMinutes==34)) { if(TimescoreSeconds==10) { Life--; } }
Answer by LCStark · Sep 30, 2018 at 04:06 PM
I don't know if I understand correctly what you want to do and what your problem is, so correct me if I'm wrong. You want to decrease the "Life" variable by 1 at a specific time, but since your code runs many frames per second, you actually subtract much more than just 1?
If that is the case, you can use a separate boolean field to check whether you have already subtracted 1.
private bool lifeSubtracted;
void Start() {
lifeSubtracted = false;
}
void Update() {
...
if ((TimeScoreHours==16)&&(TimescoreMinutes==34)) {
if(TimescoreSeconds==10 && lifeSubtracted == false) {
Life--;
lifeSubtracted = true;
}
}
}