Hi All, I’ve been beating my head against a brick wall here for a few days now… And so I turn to the forums for help…
the problem:
I have a spawn object, which has an array of SpawnPoints, when a player joins, i want an index of the spawnpoints to increase, so when the server spawns, he spawns in “slot 1” and then when anyone else connects, they spawn in slot 2, etc etc…
I’m using RPCMode.AllBuffered, and I’m right in thinking that this should, basically, send a list of these messages to any new client. (So for example, if there are 12 players it sends “RequestSpawn” 12 times to a new client)
Here’s my code. It’s such a simple thing to do but I just can’t see the method yet and it’s driving me insane…
networking.js
var isserver = false;
var SpawnPoints : SpawnPoint[];
var current_spawn = 0;
var spawn_here : SpawnPoint;
@RPC
function RequestSpawn()
{
inc_spawn();
SetSpawnPoint();
}
function inc_spawn()
{
current_spawn += 1;
}
function SetSpawnPoint()
{
spawn_here = SpawnPoints[current_spawn];
}
then in the “carprefab.js” script, I do this:
var playerPrefab : Transform;
var networking : networking;
private var spawn_id = 0;
private var spawn_here : SpawnPoint; //<--- this isn't actually used.
function OnNetworkLoadedLevel ()
{
//networking.RequestSpawn();
networkView.RPC ("RequestSpawn", RPCMode.AllBuffered);
var pos : Vector3;
pos.x = networking.spawn_here.transform.position.x;
pos.y = networking.spawn_here.transform.position.y;
pos.z = networking.spawn_here.transform.position.z;
//Debug.Log(pos);
Network.Instantiate(playerPrefab, pos, networking.spawn_here.transform.rotation, 0);
}
This surely, is so easy someone must know how to do this… (very basically it’s a player count that is “got” from the server when a client connects… Does anyone have any alternative methods for getting variables off a server?