Spawn Random Enemy

I want to make a script that will pick one game object out of a few and instantiate it. also, i want it to be able to change the number of gam objects that i can assign with a variable, so that if i come up with another enemy, i can just change the variable. C# please!

Something along this way should do what you ask for. In the editor add gameobjects to the array, then when you want to spawn the enemy just call SpawnRandom().

class Spawner : MonoBehaviour
{
	public GameObject[] objects;
	
	public void SpawnRandom()
	{
		Instantiate(objects[UnityEngine.Random.Range(0, objects.Length - 1)]);
	}
}

Hi there!

I really love this script. But being a beginner in the programming scene, I must ask, can someone tell me how to make my enemies move on an X axis upon their apparence on screen ? Thanks in advance :slight_smile:

how to make spawn enemy with position camera

/