- Home /
How can I create a script to create and then randomly select 1 of 3 spawning points?
I am trying to create a script where I can set 3 spawning points, and when I start the game, it will spawn me in one of those places. Thanks
Answer by fafase · Aug 23, 2012 at 09:15 AM
var spawnPoints:Vector3[] = new Vector3[3];
function Start(){
spawnPoints[0]=Vector3(x,y,z);
spawnPoints[1]=Vector3(x,y,z);
spawnPoints[2]=Vector3(x,y,z);
}
function ChooseLocation():Vector3{
var location:vector3 = spawnPoints[Random.Range(0,4)]
return location;
}
dude, consider, in practice the spawn points would be $$anonymous$$AR$$anonymous$$ERS (I mean, simply empty game objects) in the scene
you'd give them all a tag, understandable name or whatever and choose one randomly.
there's no point having an entire game engine, etc, and reverting to machine code :-)
True, but thinking in terms of memory management, I would think an array of Vector3 is smaller than an array of GO since it holds the whole transform, name, tag and other overhead information. Does anyone know how big is an empty game object?
it's absolutely no problem man, honest. any typical game would have about 8 zillion game objects of all types, a few empty ones means nothing
i've never seen any title that doesn't have dozens if not 100s of "position markers" everywhere in the scene.
nevertheless pedagogically your example is very sound! :)
Your answer
Follow this Question
Related Questions
For Loop isn't working properly! 1 Answer
i want to spawn randomly 1 Answer
Random Drops 2 Answers
Room generator spawn 1 unique room 1 Answer
How to generate random objects? 1 Answer