- Home /
Stop Timebar decrease by pressing key button
Hi guys, My problem is to stop decreasing my Timebar. If I press the "B" key, it needs to stop decreasing.
This is my current JavaScript for the Timebar, but I can't figure it out how to fix my problem. Maybe you can.
var totalTime = 25.0;
var remainingTime = 25.0;
function Update() {
if (remainingTime > 0.0)
remainingTime -= Time.deltaTime;
}
What I mean is by example, as you can see, totalTime = 25 and it decreases to 0. So by example if totalTime is decreased to 7 and I press the "B" key button. Then totalTime will stop with decreasing.
Please help :D
EDIT
Someone please help, my problem is still unsolved :(
Answer by Theinsanekiller · Jun 13, 2013 at 05:20 AM
You just have to add one extra condition, if (remainingTime > 0.0 && !Input.GetKey(KeyCode.B)) remainingTime -= Time.deltaTime
I actually use the "B" key button in another script. So totalTime and remainingTime are static vars. And this doesn't work. I did the same before, but it's not working.
First of all where are u decreasing your totalTime? I am not able to see the condition for it.
Your answer
Follow this Question
Related Questions
How to end an animator animation using time? 0 Answers
How to pause Time(Time.timeSinceLevelLoad) 1 Answer
Track time between 1 Answer
Stop Watch start when told 2 Answers