Assets\Scripts\GameManager.cs(32,22): error CS1001: Identifier expected I don't know what to do

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
public float velocidad = 2;
public GameObject col;
public Renderer fondo;

public List cols;
// Start is called before the first frame update
void Start()
{
// Crear mapa.
for (int i=0; i<21; i++)
{
cols.Add(Instantiate(col, new Vector2(-10 + i, -3), Quaternion.identity));
}
}

// Update is called once per frame
void Update()
{
fondo.material.mainTextureOffset = fondo.material.mainTextureOffset + new Vector2(0.2f, 0) * Time.deltaTime;

//Mover mapa
for (int i=0; i<cols.Count; i++)
{
if (cols(i).transform.position.x <= -10)
{
32 cols.(i).transform.position = new Vector3(10, -3, 0);
}

cols(i).transform.position = cols(i).transform.position + new Vector3(-1, 0, 0) * Time.deltaTime * velocidad;
}
}
}

first thing - learn to use code tags so people stand a chance of reading that stuff
it also helps to indicate which line the complaint is, but then code tags would mean we dont have to count

however cols(i) sounds like what its complaining about and to be fair, that seems reasonable. what do you think that does?

Use cols* not cols(i) to get an item in an array/list.*
And please use code tags in the future, so we can quickly find where is line #32 (the 32 in the error message refers to the line number).
Also make sure your cols list is initialized (public List<GameObject> cols = new List<GameObject>()). In this case it shouldn’t be a problem since it’s a public list that Unity can serialize, so it should be initialized by the Unity serializer, but if it was private, or a list of objects Unity can’t serialize, you’ll get a NullReferenceException when you try using it.

1- I use cols, not cols(i) but in the forum I can’t put so I replace with (i) but just in the forum.
2-Thanks, but I still do not understand what I need to do
3- I write where is the line 32
4- I don’t understand what are code tags

Code tags:

Click on it, and paste your code inside. It’ll format it nicely and display line numbers (it’ll also allow your to use )

Line 32: cols. _=> cols**_

Thanks you very much for everything!

1 Like