So, I already got a spawn point script ready. It's simple, but that's really all I need. But now I want to have multiple spawn points. Basically, what I mean is that like, if you reach Point B, then whenever you die, you will spawn to point B. If you reach point C, whenever you die then you'll spawn to point C. Something like that. This is the script I'm using. Any reccomendations? It's a 2.5D Platformer by the way.
So here's how I would do this. Instead of just having a crapton of Transforms in your script (which is messy), you can do something like this instead.
Set up a game object, and have children game objects as the actual "spawn points". This way, you can move them around the world, and even attach an editor gizmo to them if you want. Your Hierarachy would look something like this:
Spawnpoints |- Spawnpoint A |- Spawnpoint B |- Spawnpoint C |- Spawnpoint D |- etc...
So now, on the "Spawnpoints" game object, you can find all the "Transform" children and load them into an array, like so:
And now you have an array of all of your spawnpoints (Spawnpoint A, Spawnpoint B, etc). Want to add another one? Just create a new gameobject spawnpoint, and add it to the children list along with the others. The script will find it automatically, and you don't need to add it in manually. :)
answered Jun 24, 2010 at 04:45 AM