I have a Unity Universal 2D project set up and this script to create a grid of tiles:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
public class GridManager : MonoBehaviour
{
[SerializeField] private int gridWidth, gridHeight;
[SerializeField] private T tile;
[SerializeField] private Transform camera;
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < gridWidth; i++)
{
for (int j = 0; j < gridHeight; j++)
{
var newTile = Instantiate(tile, new Vector3(i, j), Quaternion.identity);
newTile.name = $"Tile {i} {j}";
bool offset = (i % 2 == 0 && j % 2 != 0) | (i % 2 != 0 && j % 2 == 0);
newTile.Init(offset);
}
}
camera.transform.position = new Vector3((float)gridWidth / 2 - 0.5f, (float)gridHeight / 2 - 0.5f, -10f);
}
// Update is called once per frame
void Update()
{
}
}
and it does work, as I can see the objects in the hierarchy being created
but I don't actually see my objects in the game view (the sprite renderer has a white colour), so I'm a bit confused about why