How to spawn a GameObject by name?

Hello! I am making an enemy spawner right now, and I want it to randomly select an enemy to spawn in a given amount of seconds. Here is my code, it is hard to explain without using the code.

#pragma strict
var spawnMin = 1;
var spawnMax = 10;
var enemyNum = 1;
var NOE = 3;
var spawnedEnemy = Transform;//I also tried a Game Object, it doesn't work
var enemy = '';
function Start () {
InvokeRepeating("SpawnEnemy", 10, Random.Range(spawnMin, spawnMax));


function Update () {


function SpawnEnemy(ifnum : int){
enemyNum = Random.Range(1,NOE);
while(ifnum < NOE){
enemy = ('enemy'+ (NOE - ifnum).ToString());//Each enemy is named enemy, then a number. Example: enemy1, enemy2

if(enemyNum == NOE - ifnum){
spawnedEnemy = Instantiate(GameObject.Find(enemy), transform.position, Quaternion.identity);//This is supposed to spawn the enemy which corresponds to enemyNum
ifnum += 1;

I’m getting the error 'Cannot convert ‘Unityengine.GameObject’ to ‘System.Type’ (I can’t copy and paste from the error window, so that’s basically what the error is), so I think it has to do with the fact that I’m using GameObject.Find to spawn a certain enemy. I tried it with Transform.FindObjectsOfType, but that didn’t work either. How can I get it to spawn

Your problem is this:

var spawnedEnemy = Transform;

You mean

var spawnedEnemy : Transform;

At the moment you set you spawnedEnemy variable = to the type of Transform (not a variable holding one!)

Plase use prefabs for spawing enemy