- Home /
give instantiated objects positions from from objects in list
hi!
i want to instantiate an object when pressed play. therefore i have a few different empty objects in the game that should give the instantiated objects the positions, where they could be placed. it should be random so that the instatiated objects will be placed at different places everytime i press start. i can not get the code right for this. what have i written wrong? could anybody please help me? thank you!
here is my code:
public var instPrefab : Transform; public var instAmount : int = 5; public var instRange : Vector3 = Vector3( 5, 0, 2 ); var instantiatePoints : List.;
function SpawnObjects() { instantiatePoints = new List.(GameObject.FindGameObjectsWithTag("InstantiatePoints"));
var instPosition : Vector3;
for (var i : int = 0; i < instAmount; i++)
{
for (var points in instantiatePoints)
{
for (var xi : int = 0; xi < points; xi++)
{
xi = Mathf.Round(Random.value * (instantiatePoints.length-1));
instPosition = points[xi].transform.position;
Instantiate (instPrefab, instPosition, Quaternion.identity);
}
}
Your answer
Follow this Question
Related Questions
How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer
Prefab instantiating problem 1 Answer
Object instantiates on top of the previous object 2 Answers
Instantiate breaking at certain positions? 0 Answers
How can I get a GameObject's transform in game and set that to a variable? 1 Answer