[quite solved] List or array of game assets

Hello everybody, sorry for the very noob question,

I am creating a serie of prefabs that i want to randomly spawn as kind of tiles on game background, i am trying to do like alist or array of GameObjects, and I am not able to make it work, also i wish to get suggestions on a more elegant and effective way to do so…

Thanks

    [SerializeField]
    private GameObject SpaceBkgnd_0;
    [SerializeField]
    private GameObject SpaceBkgnd_1;
    [SerializeField]
    private GameObject SpaceBkgnd_2;
    [SerializeField]
    private GameObject SpaceBkgnd_3;
    public GameObject[] EmptyBkgnd = new GameObject[] { SpaceBkgnd_0, SpaceBkgnd_1, SpaceBkgnd_2, SpaceBkgnd_3 };

    
    void Start () {
        
         for (int x = -6; x < 6; x+=2)
        {
            for (int y = -6; y < 6; y+=2)
            {
                Instantiate(EmptyBkgnd[Random.Range(0,3)], new Vector3(Mathf.RoundToInt(playerShip.transform.position.x) + x, Mathf.RoundToInt(playerShip.transform.position.y) + y, 0), Quaternion.identity);
            }
        }
    }

and writing like this:

  public GameObject[] EmptyBkgnd;

    void Start () {
        EmptyBkgnd[0] = SpaceBkgnd_0;
        EmptyBkgnd[1] = SpaceBkgnd_1;
        EmptyBkgnd[2] = SpaceBkgnd_2;
        EmptyBkgnd[3] = SpaceBkgnd_3;

give me a different error: Array index is out of range.

[SerializeField] public GameObject[] SpaceBkgnd;

The inspector can handle this already. Don’t enumerate your variables like that, that’s like the worst thing a rookie can do and a clear indicator that you’re doing something wrong.

done that way and it works thanks…

Also I see that instantiating a bunch of tiles the way i do, with two nested for loops results in strange white line spaces between them that appears sometimes while moving the camera around the scene… I wonder if i can avoid that only if i create a tilemap and use that…

I’ve seen that somewhere on the internet. Look it up, it has a solution, I think turning off anti-alias or sth.