It's Unity C#. I have a problem with my code here. My goal is to keep cubePositions
in a list which I'll use later. I am kepeeng it in a weird way. I used Vector3 but it gave me the same error. I am getting the error: ArgumentOutOfRange. My best guess is that the value replaces the last one. Also, all of my game objects called the same. print() is not a problem.
Thank you!!!
Here is my code:
public class MapAccess : MonoBehaviour
{
List<float> cubePositionsX = new List<float>();
List<float> cubePositionsZ = new List<float>();
void Start()
{
foreach (GameObject cube in GameObject.FindGameObjectsWithTag("Cube"))
{
cubePositionsX.Add(cube.transform.position.x);
cubePositionsZ.Add(cube.transform.position.z);
print(cubePositionsX[0]);
print(cubePositionsX[1]); //The problem is here. Unity said that ArgumentOutOfRange
}