Weird result using Time.time
Hi,
I'm trying to export some time data into a text file but I'm getting some weird results. The way I'm going about is by calling InvokeRepeating() on a function that I made called RecTime() shown below.
void RecTime()
{
time.Add(Time.time); //Time.fixedTime
}
Where the variable time is a private variable with the following type List, that I initialize in the Start() function using "new List". I've got a GUI button set up that calls CancelInvoke() to end the repeating calls as well exporting the data stored in variable time into a text file.
void Start () {
time = new List<float>();
rb = GetComponent<Rigidbody>();
InvokeRepeating("RecTime", tSample, interval);
}
My issue is that instead of seeing different values for time I get the following line repeated System.Collections.Generic.List`1[System.Single].
Does anyone know what could be going wrong? The documentation for Time.time says that "The time at the beginning of this frame (Read Only). This is the time in seconds since the start of the game." So I'm assuming that because of InvokeRepeating() I'm calling Time.time in different frames and so I should be getting different time values stored in the List I made and those values should be exported to a file. But that's just not the case.
If I'm misunderstanding something about Time.time or if anyone sees a problem with the code or logic that I've posted please let me know, I really do appreciate it. Thanks in advance!
P.S. I also tried using Time.fixedTime but that gave the same result, if that makes a difference.
Answer by Commoble · Mar 05, 2017 at 04:57 AM
You're using Time.time properly, but you're probably exporting your data to the text file wrongly. Make sure you're exporting the actual float values inside the list, not the list object itself.
Oh ok, yeah I was using some modified old code that wrote a List of Vector3's to a file and I didn't update it properly to meet my needs here. Thanks a lot for the help, I honestly appreciate it!