Search code examples
c#unity-game-enginesprite

Sprite Renderer in Unity2D not functioning


View of the Inspector for the Tile prefab

Tile script

Grid Manager script

I am attempting to generate a grid of squares that form a checkerboard pattern. When line25 of the Grid Manager is removed, it generates a plain white grid perfectly fine, but when I do run init to introduce the checkerboard colors, all of the sprites do not render and the tiles are invisible. The colors are assigned to the tiles when they are generated, but the Sprite Renderer is not drawing them.

Expectation: Running init should assign the colors to the generated tiles, making a checkerboard pattern instead of a plain white grid.

Result: Running init assigns the proper colors to each tile, but the Sprite Renderer doesn't render them anymore, resulting in a blank Scene view and Game View


Solution

  • Your colors have an alpha of zero. In the inspector, at the bottom of the colors, you can see a black line. This fills up with white as it is set to be less transparent. You can click on it and set the alpha, or in the script you can set the .a on the color to 1.