Unity: Spawning enemies on a procedurally generated map
<p>So I've been Googling this for a while, but I don't really know what to look for, so I'm gonna ask all of you nice people for help instead.</p>

<p>I'm working on a procedural level creator for my first game. Part of the code is inspired by the tutorial here, but I try to do as much as I can on my own. Anyways, here's the code I need help with, which is probably ugly as all hell, and I'll explain what I need help with after:</p>

<pre><code>Vector3 RandomPosition ()
{
    int randomIndex = Random.Range (0, gridPositions.Count);

    Vector3 randomPosition = gridPositions [randomIndex];

    gridPositions.RemoveAt (randomIndex);

    return randomPosition;
}


void LayoutObjectAtRandom (GameObject[] tileArray, int minimum, int maximum)
{
    int objectCount = Random.Range (minimum, maximum);

    for (int i = 0; i &lt; objectCount; i++)
    {
        Vector3 randomPosition = RandomPosition ();

        GameObject tileChoice = tileArray [Random.Range (0, tileArray.Length)];

        Instantiate (tileChoice, randomPosition, Quaternion.identity);
    }
}

void spawnTomcats () // Figure out a way to use the RandomPosition to exclude used tiles in enemySpawn
{
    int enemyCount = (int)Mathf.Log (level, 2f);

    for (int i = 0; i &lt; enemyCount; i++)
    {
        Vector3 enemySpawn = new Vector3 (columns + (Random.Range (0, 5)), rows - (Random.Range (7, 14)), 0f);

        GameObject tileChoice = enemyTiles [Random.Range (0, enemyTiles.Length)];

        Instantiate (tileChoice, enemySpawn, Quaternion.identity);
    }

public void SceneSetup (int level)
{
    BoardSetup ();
    InitialiseList ();
    spawnTomcats ();

    LayoutObjectAtRandom (impassableObjects, impassableCount.minimum, impassableCount.maximum);

    Instantiate (heatCat, new Vector3 (columns - 8, rows - (Random.Range(7, 14)), 0f), Quaternion.identity);
}
}
</code></pre>

<p>So, what I need is for "Vector3 enemySpawn" to choose a tile within the specified parameters, but that aren't already used by the instantiating of impassableObjects in the SceneSetup function. Everything works on the spawning part, but my "Tomcats" sometimes spawn on top of impassableObjects. I've tried integrating the RandomPosition() method several ways, but haven't really succeeded. </p>

<p>If you need any more information, like my variables, let me know! I'm not really sure how much is needed as I'm still a beginner.</p>

<p>Every piece of advice will be greatly appreciated.</p>

<p>Joel Crosby.</p>