- Home /
Network spawning
hey, new to networking here, and I can't seem to figure out how to get past this:
I've got a scene set up with 4 spawn points, I need each player (max of 4) to choose a spawnpoint and spawn there. The scrip I currently use finds all the spawnpoints at random and spawns a player there. This is of course a problem, as players are likely to spawn right on top of one another at the same spawnpoints.
var spawnpoints : GameObject[] = GameObject.FindGameObjectsWithTag ("Spawnpoint");
var spawnPoint : Transform = spawnpoints[Random.Range(0, spawnpoints .length)];
var newTrans = Network.Instantiate(playerPref, spawnPoint.transform.position, spawnPoint.transform.rotation, 0);`
Any suggestions on how to do that?, i've tried setting up arrays, and all that but i'm not so sure i'm doing it right. Each player has there own unique "Network.player" ID, when i debug.log this it spits out a number, but that number can't be used like an int.
what i was thinking was something like var mySpawnpoint : Transform = spawnpoints[Network.player]
but that doesn't work :(
I'd appreciate any help you can give.
Answer by syclamoth · Jan 23, 2012 at 06:36 AM
How about this? It's a bit hacky, but at least it's a one-line solution.
var mySpawnpoint : Transform = spawnpoints[System.Int32.Parse(Network.player.ToString())];
holy devil! Sir, you are my favorite person on the planet right now, TY!