Hello, I’m new to scripting in Unity and I would like to create a SpawnPoint that randomly spawns objects at the same location (I must set the size and put the gameobjects that I want to randomly spawn, that would be awesome) to that position and in x amount of the time it respawns again and again…
var Object : GameObject;
var SpawnPoint : GameObject;
InvokeRepeating("SpawnEnemy", 5, 10);
function SpawnEnemy()
{
Instantiate (Object, SpawnPoint.transform.position, Quaternion.identity);
}
I just need the randomly spawning objects. Thanks!
I meant to spawn different kind of objects (like if I put some prefab it spawns that prefab, but I can but as much prefabs as I want so they can randomly spawn).
To spawn a random prefab you need to make an array of game objects to pull from. Then use the Random function to randomly grab a game object from your list and then spawn it from your spawn point.
public GameObject[] enemies;
void Spawn(){
int randomEnemy = Random.Range(0, enemies.Length);
Instantiate(enemies[randomEnemy, spawnPoint.transform.position, transform.rotation);
}