Hi there,
I begin my game by starting a coroutine:
void Start() {
StartCoroutine(ImportAssets());
}
In here, I wait for two seconds, and then save the current time:
IEnumerator ImportAssets() {
yield return new WaitForSeconds(2);
startTime = Time.time;
}
Then, in my Update function I test to see if a character needs importing, if it does I disable the script while it imports. (Ignore the first if statement for a moment.)
void Update() {
if (itemsLoaded == total) {
Helpers.Log(Time.time);
Helpers.Log(startTime);
Helpers.Log("Loaded in", Time.time - startTime);
total = 0;
enabled = false;
}
if (readyCharacters.Count > 0) {
enabled = false;
StartCoroutine(ImportCharacterObjects(readyCharacters[0]));
}
}
Importing the characters takes a lot of work, and actually holds a few frames for a couple of seconds. Once all the characters are imported, that if statement runs fine, however Time.time is definitely incorrect.
- startTime logs out at ~2.002099 (Which is correct)
- Time.time logs out at ~4.877523 (Which is incorrect, using a stop watch I measure at least 8 seconds)
- As such, Loaded in logs out at ~2.875424, which is obviously also incorrect.
I’ve had the thought that maybe locking up frames in the game throws out its time counter? Otherwise I’d love to find out what’s going wrong, as I need an accurate timer for this importing process.
Thanks in advance!