This question was
closed Feb 11, 2016 at 08:48 AM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Question by
hilmimarzuqi · Feb 10, 2016 at 08:06 PM ·
error messagelistspositions
How should I add a transform.position on a List?
I need to do a list of positions of an object as time passes, so I'm having an error whenever I try to add it to a list variable. I'm trying to add it on a list and later use something like Debug to display the list on the console.
Here is the code snippet I'm using:
public List<Transform> listOfPosition = new List<Transform>();
void Update (){
if(Input.anyKey)
{
Debug.Log("A key or mouse click has been detected");
listOfPosition.Add(transform.position.x);
listOfPosition.Add(transform.position.y);
}
The error that I've been getting is :-
1) The best overloaded method match for 'System.Collections.Generic.List<UnityEngine.Transform>.Add(UnityEngine.Transform)' has some invalid arguments
2) Argument '#1' cannot convert 'float' expression to type 'UnityEngine.Transform'
I have gone through the code multiple times and have referred to a number of sources but I still can't manage to see a workaround.
Comment
Best Answer
Answer by Jessespike · Feb 10, 2016 at 08:32 PM
transform.position is a Vector3
public List<Vector3> listOfPosition = new List<Vector3>();
//....
listOfPosition.Add(transform.position);
Is this true if i added a Time.deltaTime in it as well?