- Home /
Question by
PRogrammer546 · Oct 04, 2017 at 09:51 PM ·
c#timenot workingint
Checking for start of second in waitforseconds
Hello!
I have some code which increases an integer by 1, and a want it to log when the time is equal to 5. Here is my current code:
public Text time;
int daInt = 1;
public int timeRunning = 1;
string theText;
public bool startSecond;
int theTextint;
void Start () {
StartCoroutine( HandleIt() );
}
private IEnumerator HandleIt(){
if (timeRunning != 0){
startSecond = true;
theText = time.text;
int.TryParse(theText, out theTextint);
daInt = theTextint + 1;
yield return new WaitForSeconds(1f);
time.text = daInt.ToString();
if(time.text == "5" && startSecond == true){
Debug.Log("event 1 fires");
startSecond = false;
}
startSecond = false;
StartCoroutine( HandleIt() );
}
}
When i run the game, when time is 5 it logs twice, not once. Any ideas on how to fix?
Thanks!
Comment
Your answer
Follow this Question
Related Questions
C# Check If Minutes equal some denomination of 5 3 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Increase text size over time c# 2 Answers
How to transfer time script to 24 hours and not decimals 1 Answer