|
Hey guys, I'm not new to the forums/answers exactly, but it's the first time I myself have needed to ask a question. I usually google around and find an answer to my question without having to ask one myself. Well, here goes. I have this progress bar that starts once I press a button. I'm trying to make it so that even after I let go of said button, it picks up from where it left off on the progress bar. At the moment, if I let go of the action button and then press it again the progress bar just starts all over again. It's kind of annoying and a killer to my game mechanics. The bar itself also decreases back to 0 over time if left alone long enough (which is intentional). Here's the code in question: I picked up some of the code from one of the questions in here which is what most of the commented out parts are all about. Any steer in the right direction would be appreciated.
(comments are locked)
|
|
in youre else statement remove the line "barStarted = false;". Although the bar didn't start over, it did shoot to the end of the progress bar. I'm guessing that it's because that else statement is linked to this part: if(Input.GetButton("Action")) { if( barStarted == false ) { barStarted = true; barDisplay = 0; barStartTime = Time.time; } Thanks for the input though. :)
Sep 11 '12 at 08:11 PM
luiscmendez
Its because how you are storing the time. You need to take a timestamp of when they release the button then add Time.time - timestamp to the barStartTime.
Sep 11 '12 at 08:14 PM
PAEvenson
Okay, thanks. I'll take a look at the Unity Script Reference about timestamp (never worked with them) and if I figure out how to make it work, I'll update the post. Thanks again!
Sep 11 '12 at 08:22 PM
luiscmendez
Sorry when I say timestamp I just mean store the Time.time in a variable so you can access it later when they push the fire button again.
Sep 11 '12 at 08:24 PM
PAEvenson
Oooh, got it.
Sep 11 '12 at 08:34 PM
luiscmendez
(comments are locked)
|
