x


Multiple Spawn Points

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.

var spawnpoint1 : Transform; var spawnpoint2 : Transform;

function OnTriggerEnter(other : Collider) { if (other.tag == "Player") { other.transform.position = spawnpoint1.position; } }

more ▼

asked Jun 24, 2010 at 12:55 AM

Flipbee9 gravatar image

Flipbee9
88 47 44 46

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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:

Transform[] spawnpoints = GetComponentsInChildren(typeof(Transform)) as Transform[];

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. :)

more ▼

answered Jun 24, 2010 at 04:45 AM

qJake gravatar image

qJake
12.7k 92 137 214

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x457
x277

asked: Jun 24, 2010 at 12:55 AM

Seen: 2421 times

Last Updated: Jun 24, 2010 at 05:20 PM