Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question How to save Time.time data into a list

Discussion in 'Scripting' started by tsuiisaac02, Mar 7, 2023.

  1. tsuiisaac02


    Nov 13, 2022
    Thanks for taking the time to read this message.

    In unity I am aiming to record the Z euler angle of an game object every fixed time interval and output this as a CSV file, with the time in the left collumn and the corresponding euler angle in the second collumn.

    I recieve this error

    Assets\scripts\debug\ConcatArray.cs(28,21): error CS0029: Cannot implicitly convert type 'float' to 'System.Collections.Generic.List'

    This is my attempt and have tried changing the variable type of 'Time count' to 'System.Collections.Generic.List', but i still recieve the same error.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Linq; // allows for concat?
    6. public class ConcatArray : MonoBehaviour
    7. {
    8.     public string fileName = "Assets/Resources/test.txt"; // file pathname
    9.     private List<float> AnglesOne;
    10.     private List<float> TimeCount;
    11.     private float[] DoublePendulumData;
    13.     // Start is called before the first frame update
    14.     void Start()
    15.     {
    16.         AnglesOne = new List<float>();
    17.         TimeCount = new List<float>();
    18.         DoublePendulumData = new float[] { 15, 1645, 135, 567 };
    20.     }
    21.     void RecPoint()
    22.     {
    23.         // store position...
    24.         AnglesOne.Add(transform.eulerAngles.z);
    27.         //Store time... capital T?
    28.         TimeCount = Time.time;
    30.     }
    31.     void SaveToFile(string fileName)
    32.     {
    33.         System.IO.File.WriteAllText(fileName, ""); // clear old file, if any
    35.         DoublePendulumData = TimeCount.Concat(AnglesOne).ToArray();
    36.     }
    38.     void OnGUI()
    39.     {
    40.         if (GUI.Button(new Rect(10, 10, 120, 30), "Save"))
    41.         {
    42.             CancelInvoke("RecPoint"); // stop recording
    43.             SaveToFile(fileName); // save positions
    44.         }
    45.     }
    47. }
  2. Teddy96


    Dec 2, 2019
    TimeCount is a List... so if you want to add the time to the list you do
    Code (CSharp):
    1. TimeCount.Add(Time.time);
    Bunny83 likes this.
  3. Kurt-Dekker


    Mar 16, 2013
    Please don't double post for the same typing mistakes. You can fix your own typing mistakes this way:

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    Some help to fix "Cannot implicitly convert type 'Xxxxx' into 'Yyyyy':"