- Home /
Problem is not reproducible or outdated
Can't get objects from an array instantiate at spawn points in an array
I'm trying to spawn objects from an array to spawn points in another array. The objects chosen to be spawned must be randomly chosen, but not the spawn points. I need the code to go through each spawn point and randomly choose which object will go there. Here is what I have so far and I'm sure something is wrong in it. Oh, and all of this must happen after a button is pressed.
var couch : GameObject[];
var couchSpawn : Transform[];
function Start () {
for (var i=0; i < couchSpawn.length; i++)
{
if(Input.GetButtonDown("G") == true){
//Select From Objects To Spawn
var thingToSpawn : int = Random.Range( 0, couch.length );
Instantiate( couch[thingToSpawn], couchSpawn[i].position, transform.rotation );
}
}
}
it's difficult to help with super-general program$$anonymous$$g questions like this.
if there is a VERY SPECIFIC PROBLE$$anonymous$$, please post a question explaining that
it\s very unlikely you want to do this in Start(), it's likely you mean Update()
also you would look for the ketystroke first, and only then go through the loop
consider say stackoverflow for very general progrsm$$anonymous$$g questions about loops, etc.