Is there a simple way to instantiate a random prefab out of a set?

I’m creating a tile map via pixel color values assigned to specific tiles using this code to link tiles to colors on the map.

if(tileColors[x+y*levelWidth] == tileColor){
					Instantiate(thisTile, new Vector3(x, y), Quaternion.identity);


And I’m wondering if there’s a way to set “thisTile” as a list of tiles which use of can be determined pseudo-randomly in order to set multiple tiles to one color and have them vary as the map loads?
I was thinking it would be something along the lines of making “thisTile” a variable, creating a random number generator that rolls every time this bit of script runs, listing each possible tile as a possibility for the variable to be and linking each one to the possible outcomes of the random number generator, effectively producing a psuedo-random areay of tiles based on what the number gen rolls. However I’m not at all sure how I would go about setting that up. Any help would be great thanks!

Hey there,

If you set your list of tiles to an array you can just use the random helper function to pick a random element in a the array every time Instantiate is called.

public Tile[] tiles;

public void MakeRandomTile()
   Instantiate(tiles[Random.Range(0, tiles.Length), new Vector3(x, y), Quaternion.identity);

This works about better since you can add any number of tiles and it will pick a random one each time.