Spawn object on random location

Hello, im making a game which is 98% percent finished, only lefts to randomize some objects.
I have been searching how to make script for what i need for more than a month, but nothing…

What i need is - lets say i have 10 objects. I have ~40 empty objects at specific locations around the world.
These 10 objects must spawn random inside these 40 empty objects locations and they must me 1 at a location, no more.

40 locations = 10 spawn

Store all the spawn points in a list.

Spawn the object at a random spawn point in the list and then remove the spawn point from the list to ensure that an object cannot be spawned there again.

Yeah, that is what I said, but just looks shorter.
I have tried tutorials and scripts out there, but none of them works in unity5. I know that the script should be no more than 10 rows, but I may miss something, because nothing works…

So what does your script look like right now?

var prefab : GameObject;
var spawn1 : GameObject;
var spawn2 : GameObject;
var spawn3 : GameObject;
public GameObject[spawn1, spawn2, spawn3] spawnPoints;
public int randomNum;
  function Start ()
     
      randomNum = Random.Range(0,3);
      {
     //SpawnerID = Random.Range(1, 3);
     
     if(spawn1){
     
     transform.position = spawnPoints[randomNum].transform.position;
     
     }
     
     if(spawn2){
     
     transform.position = spawnPoints[randomNum].transform.position;
     
     }
     
     if(spawn3){
     
     transform.position = spawnPoints[randomNum].transform.position;
     
     }
     }

Well, you’re mixing both Javascript and C# in the same script file. You need to pick one and go with it.

I would personally suggest C# because of many reasons.

What you’re trying to do with the spawning would require a List and I’m not so sure if Lists are available in JS.

Ok, what I have to add or delete from script ti make it work? I get some errors too, but is maybe because there is much languages inside script.

Is there someone, who has already made similar script or a tutorial, so I can see how to create this script properly? There is some tutorials in youtube about that, but they are only from random spawn inside box collider, not specific.
Think slender papers do the same, but there is no tutorials out there for them.

Try searching the unity forums, I’m sure you’ll find what your looking for. I did a quick search and found this answer. It should help you or at least point you in the right direction:
http://answers.unity3d.com/questions/1016061/random-spawnpoint-where-only-one-prefab-can-spawn.html?_ga=1.193960301.1736619861.1476974354

Here’s a Unity tutorial about Lists that will help you learn about them:

Ok, i found script that does what i want ( from slender guide ), but it just clone my items (not random spawn item i’ve added, but random spawn a clone of a item). So i find the item clones at random places, but im required to find the real ones too or is like i found nothing. You can try if you want, create 5-6 cubes, 10-15 spawn places and you will see that the real cubes stays, and clones (useless if real stays)

#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 ++ )
     {
         availableSpawnPointsList.Add( spawnPoints[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 );
       
         spawnList.Add( availableSpawnPointsList[rndPos] ); // add this to the spawn point list
       
         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[i], spawnList[i].position, spawnList[i].rotation );paper.name = "Paper";
         paper.name = "Paper";
     }
}