CS2021 Error - Unclear on Why

I’m trying to figure out what I’m doing wrong, and keep getting weird errors that don’t make sense to me, but I think I’ve got it narrowed down. Probably self-explanatory to veterans, this script should grab the array of tiles I drop in the inspector, fill a numeric array with a random number between 0 and (tileStyles), then use those numbers to choose an entry in tiles to put on the screen at x,y.

(It’s very likely there’s stuff I don’t need, as I’m cribbing from two of the tutorials, so input is welcome.)

I received error CS0201, “Only assignment, call…” etc. and it indicates the last real line of code with Instantiate.

using UnityEngine;
using System;
using System.Collections.Generic;
using Random = UnityEngine.Random;

[Serializable]
public class MakeMap : MonoBehaviour {

	public int cols;
	public int rows;
	public int tileStiles = 6;
	public int[,] gridMap;
	public GameObject[] tiles;
	private int temp;

	void Start()  {
		gridMap = new int[cols,rows];
		LoadMap();
		ShowMap();
	}

	void LoadMap()  {  //loop to fill a grid with tile numbers
		for (int x = 0; x < cols; x++)  {
			for (int y = 0; y < rows; y++)  {
				gridMap[x,y] = (Random.Range(0,tileStiles));
					}
				}
			}

	void ShowMap() {   //Loop to select a tile from the list, as the coordinates from gridMap, and instantiate
		for (int x = 0; x < cols; x++)  {
			for (int y = 0; y < rows; y++)  {
				GameObject toInstantiate = tiles[gridMap[x,y]];  //The value should identify which of the tiles to put onscreen
				Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
			}
		}
   }
}

Thanks in advance! (Edited for clarity)

The “as GameObject” part is casting the reference returned by Instantiate to a GameObject, and if you do that you must assign that referente to a variable. If you don’t care about it just don’t cast it. So, do this:

GameObject instantiatedGameObject = Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity) as GameObject;
//do something with instantiatedGameObject

or this:

Instantiate (toInstantiate, new Vector3 (x, y, 0f), Quaternion.identity);