Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

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

Discussion in 'Getting Started' started by JaYoPro, Feb 23, 2024.

  1. JaYoPro

    JaYoPro

    Joined:
    Feb 19, 2024
    Posts:
    3
    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<GameObject> 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;
    }
    }
    }
     
    Last edited: Feb 24, 2024
  2. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,026
    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?
     
  3. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    Use
    cols[i]
    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.
     
    Last edited: Feb 23, 2024
  4. JaYoPro

    JaYoPro

    Joined:
    Feb 19, 2024
    Posts:
    3
    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
     
  5. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    730
    Code tags:
    upload_2024-2-24_14-22-30.png

    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.[i] => cols[i]
     
  6. JaYoPro

    JaYoPro

    Joined:
    Feb 19, 2024
    Posts:
    3
    Thanks you very much for everything!
     
    Nad_B likes this.