- Home /
How to Reset Score and Variable Problem?
Hey everybody,
Please look at my code. Basically what I'm trying to reset delayTimerStart to 0 while continually adding delayTimerStart to newDelayTimeTotal
I understand that it is resetting to 0 because of newDelayTimeTotal = delayTimerStart;
Any help is greatly appreciated.
Thank you in advance.
Apologies about the post, it was stuck in code mode.
function stopDelayTimer () {
newDelayTimeTotal = delayTimerStart; // <-- I'm sure the problem is here
//We Call delayTimeTotalAdd Here
}
function Update () {
delayTimerGUIdisplay.text = "SCORE " + delayTimerStart;
delayTimerStart ++; //Our Timer Starts when the Player is not grounded *Works*
}
function delayTimeTotalAdd () {
//This works and keeps adding up
delayTimeTotalScore.text = "TOTAL " + delayTimer.newDelayTimeTotal;
//How Do You Reset delayTimer without resetting delayTimer.newDelayTimeTotal to 0
}
I don't understand what's happening here, what the initial values of your variables are, or why you're trying to add a value that you are setting to 0 to anything at all. Is this a timer? Why not just do this?
timer += Time.deltaTime;
And then, whenever you want to reset your timer, just to this:
timer = 0;
That's the problem. I want to keep the first value of say 5 (which would come from delayTimerStart). I then want to reset delayTimerStart to 0 but add 5 to a new variable which is newDelayTimeTotal.
So, if I got 5 the first time and 4 the second time newDelayTimeTotal would be 9 and son and so forth.
Thanks.
in start function make score total equals 0
In update function say: if (good thing happens){score = score plus 1}
if (reset thing happens) {score equals 0}
You describe exactly what you're trying to do, and it sounds like your problem isn't exactly unity related, but rather generically storing values. To be honest, I think you're solution is overly complex, and you should take a step back and analyze the best way to solve your problem, then implement it.
Answer by ShinyTaco · Feb 14, 2013 at 03:04 AM
in start function make score total equals 0
In update function say: if (good thing happens){score = score plus 1}
if (reset thing happens) {score equals 0}
This worked. Thanks.
You posted a question about timers and your answer is about scores?
in the reference the Time.time the function has a very good delay example http://docs.unity3d.com/Documentation/ScriptReference/Time-time.html
Your answer
Follow this Question
Related Questions
Variable data type for two ints (x and y) in inspector 3 Answers
Problem with variables,Problem with identifying a variable 2 Answers
How can i save a int for multiple texture. Please Read. 0 Answers
controlling the increment in the variable 1 Answer
I can't print a int.ToString() variable in a guiText.text 1 Answer