public Vector3 spawnPointInsideOfBoundsForEnemySpec(EnemySpec spec) { var targetSpawnPointCollection = spec.underwater ? SpawnPointsUnderWater : SpawnPointsAir; Collider spawnPointArea = null; //find the corner that is tagged with the same enum as the group foreach (var collection in targetSpawnPointCollection) { foreach (Transform spawnPointTransform in collection.transform) { var spawnPoint = spawnPointTransform.gameObject; var spawnTag = spawnPoint.GetComponent <EnemySpawnAreaTag>(); if (spawnTag == null) { Debug.LogError(spawnPoint.name + " does not ahave a spawntag!"); continue; } var corner = spawnTag.Corner; if (corner == spec.spawnCorner) { spawnPointArea = spawnPoint.GetComponent <EnemySpawnAreaTag>().GetComponent <Collider>(); } } } //null ref means that the air or watter pool wasn't taged with one of the enemy spawn area tags return(RandomEx.InsideBounds(spawnPointArea.bounds)); }