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.
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…
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.
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";
}
}