# [Solved] Make GameObjects spawn at custom locations (Slender like)

(Sry, maybe my English isn’t perfect)
Can I make multiple gameObjects spawn at custom locations, with custom rotation?
Or is it easyer to put all of them to their location, but only activate 8 random picked ones when the scene starts?

I want to do that like in Slender (there are 10 possible locations but only 8 pages).
Thanks!

you can define an array of Vector3s (or GameObjects) and shuffle the array, and instanctiate at the first X elements with Random rotation:
for example:
GameObject Positions;

``````function Start(){
//Shuffle the array
for (int t = 0; t < Positions.Length; t++ )
{
GameObject tmp = Positions[t];
int r = Random.Range(t, Positions.Length);
Positions[t] = Positions[r];
Positions[r] = tmp;
}
for(int i = 0; i < howmanyyouwanttoinstantiate; i++){
Instantiate(YourObject,Positions*.transform.position,Random.rotation);*
``````

}
}
if you want to randomize the rotation only on Given axes you can use
Quaternion.Euler(Random.Range(0,360),Random.Range(0,360),Random.Range(0,360));
instead of Random.rotation, you can replace the Random.range with the number you want on the axis

Ok, I found a really good script for it (AlucardJ´s Slender Guide)

You can set the spawnpoints (as much as you want) and set multiple pages (gameObjects, not prefabs) to spawn.

``````#pragma strict
import System.Collections.Generic; // to use List

public var spawnPoints : Transform[];
public var paperPrefabs : Transform[];

private var availableSpawnPointsList : List.< Transform >;
private var spawnList : List.< Transform >;

function Start()
{
ChooseRandomSpawnPoints();
SpawnPapers();
}

function ChooseRandomSpawnPoints()
{
var i : int = 0;

availableSpawnPointsList = new List.< Transform >();
spawnList = new List.< Transform >();

// add all spawn points to a list
for ( i = 0; i < spawnPoints.Length; i ++ )
{
``````

}

// choose a different random position for each paper prefab
for ( i = 0; i < paperPrefabs.Length; i ++ )
{
var rndPos : int = Random.Range( 0, availableSpawnPointsList.Count );

availableSpawnPointsList.RemoveAt( rndPos ); // remove this from the available points list
}

}

function SpawnPapers()
{
// spawn paper at each location
for ( var i : int = 0; i < paperPrefabs.Length; i ++ )
{
var paper : Transform = Instantiate( paperPrefabs, spawnList_.position, spawnList*.rotation );paper.name = “Paper”;
paper.name = “Paper”;
}
}*

It works fine, but I´ll try @MagicoCreator´s script, too._