Well, your time remaining is whatever is in the variable CDTimer. If you want to start with a different amount of time, you need to put a different number into that variable.
If you have a string but you want to interpret it as a number, you may want to use something like float.TryParse(). If the string is more than just a single number (for instance, if it’s something like “10:52”) then you may need to do something more complicated; either pre-process the string to isolate the information you want, or use a more generalized parsing algorithm.
OK, so get the value from those fields using expressions like “hoursCDTField.text” and then feed it into a function like int.TryParse or float.TryParse.
I think it’s already converted as the clock time reads what I set it to in my input fields, it’s just that when I start the timer it’s not using the time already set on the clock, it seems to just start it at all zeros. I should mention that both the hours and seconds are in two different input fields. I think the problem is in here somewhere:
Where is the code where you are actually setting CDTimer to what was typed in the input fields? All I see is you set some UI Text components to what is in the input fields, but not where you also adjust CDTimer.
There needs to be some code which parses the input from the input fields, converts that to a float, and sets CDTimer.
The way your code is written “the watch” is the CDTimer variable itself. So yes your statement is true, the problem is you’ve skipped the step of setting the watch.
Computers are like evil genies: they give you exactly what you ask for, not what you meant. Computers do not have common sense. They will not “get the gist” of your code or infer your goal. They will follow your instructions exactly as you wrote them, to the letter, no matter how ridiculous the result.
The first code you posted sets all of your fields based on the value of the variable “CDTimer”. It doesn’t matter what was in those fields before; the ONLY thing that matters is the value stored in that variable.
The computer does not know that you are trying to enter a number and count down from that. It’s just doing what you told it to do.
In your code you update the watch by subtracting Time.deltaTime from CDTimer. You then set separate integers for hours/minutes/seconds from the value of CDTimer, and you use those separate variables to update some UI Text components to display the time to the user.
When you’re taking input from the user, you’re taking the string values of those input fields and setting those same UI Text components. But the UI Text components are just for displaying the timer to the user, they aren’t the timer itself, and the next time you start the watch again it is going to subtract Time.deltaTime from CDTimer, the same ints again, and the UI Text components, all based on the value of CDTimer. Everything in your code runs off CDTimer, so if you want to change the value of the timer from user input, the only thing that actually matters as far as actually setting the timer is setting the CDTimer variable itself.
Think of it like this. You’ve got a computer, and you have a monitor. CDTimer is the computer, and the UI Text fields are the monitor. You now want to shut down and restart the computer, so you go to the monitor and press the power button to shut it off, then press the power button to turn it on. Surprise! The computer didn’t restart, and it is just displaying the same thing it did before you tried. Why?
You’re effectively doing the same thing here. When you’re taking the user input, you’re only using the input to update the user friendly display of the timer, but not the timer itself. The timer itself again is the CDTimer variable in your code. Take the input from the input fields, and use that to update CDTimer, since everything else in your watch is driven off the value of CDTimer.
Ahh, I get it so the UI text is just simple being updated by my:
// Set Watch Time To Input Fields For CDT Timer
hoursUI.text = hoursCDTField.text;
minutesUI.text = minutesCDTField.text;
But what you are saying is the real time value is being stored in:
float CDTimer;
So how for example would I actually change the value of the float CDTimer with the value from my input fields??
I do have those set in the inspector to only accept numerical values and only allow 2 digits to be typed into each field, not that I believe they are related in any way to my problem.
I believe also that I’m storing each value separately according to what I have here: