#Help me pls =)
1 messages · Page 1 of 1 (latest)
Hello, I have a trouble while making my rhythm game. This is my code:
IEnumerator timer()
{
TimeSpan d = TimeSpan.FromSeconds(duration);
string dur = string.Format("{0:D2}:{1:D2}", d.Minutes, d.Seconds);
int index = 0;
audio.loop = true;
audio.Play();
float waitAmount = 0.1f;
while (true)
{
if (current >= duration) break;
yield return new WaitForSeconds(waitAmount);
DateTime fromdt = DateTime.Now;
float mfrom = fromdt.Millisecond;
current += 0.1f;
TimeSpan c = TimeSpan.FromSeconds(current);
ndur.text = string.Format("{0:D2}:{1:D2}", c.Minutes, c.Seconds) + " / " + dur;
if (data.timestamp[index].time == string.Format("{0:D2}:{1:D2}:{2:D2}", c.Minutes, c.Seconds, c.Milliseconds))
{
gen.Generate(data.timestamp[index].x, data.timestamp[index].y);
if (index < data.timestamp.Count() - 1) index++;
}
displayer.value = current;
DateTime todt = DateTime.Now;
float mto = todt.Millisecond;
Debug.Log(mto);
Debug.Log(mfrom);
waitAmount = 0.1f - ((mto - mfrom) / 100);
Debug.Log(waitAmount);
}
}
But even i checked the start and the end of code execution and subtract them. When the music is over, the timer is still going. They should end in the same time. After testing several time, the delay was like about 15 seconds, pls help!
In the break
if(current >= duration) break;
It worked fine, when the current's value is greater or equal to duration it will just exit the loop
No i mean, the while loop speed is not same as the music
Not syncing
Everything work fine except for that
Test the condition itself
Wdym
The condition that doesn't fire - current >= duration test what's happening there.
You need to debug everything
Examine values
Fire?
Oh u mean execute
Ok i will test it when i get home, im outside for dinner rn. If its possible, pls do not close the thread. I will report any issue i got after i get home and test it. Thanks =D
Thread is active 24 hours by default. You can repost link to it with a reminder what it is about later.
Oh ok, got it!
ok i tried, still the same
the loop still doesnt sync with the music
As previous guys said, you need to debug and print out our times to see why,