Hi
I am trying to use unity’s networking example
and seperate the clients so each can select his own game, while keeping the multiplayering for each game
(in the original project:
when one player selects the “car” game
the same “car” game is loaded on all players connected to the same server.
I want players 1…5 to play “car” game while players 6…9 play “third-person” game)
I was able to change the level loading (so now each player selects his game),
and I changed the spawn scripts so for the third-person game I have:
var playerPrefab : Transform;
function Awake(){
networkView.group = 5;
}
function OnNetworkLoadedLevel ()
{
Network.Instantiate(playerPrefab, transform.position, transform.rotation, 5);
}
function OnPlayerDisconnected (player : NetworkPlayer)
{
Debug.Log("Server destroying player");
Network.RemoveRPCs(player, 5);
Network.DestroyPlayerObjects(player);
}
but I have 2 problems:
p1. the prefab is instantiated on all connected screens,
so if player1 instantiates a player on third-person game, while player2 runs the car game - the third-person prefab is instantiated also on player2’s car game (you can see it on the scene view if you run the car game on unity).
I don’t get why the instantiation is not limited to the players who play the same game only (group 5)
p2. the prefabs are not buffered so when a new player joins the game - all can see him but he can see only himself
SO…
I tried another way:
var playerPrefab : Transform;
private var isInstantiated : boolean = false;
function Awake(){
networkView.group = 5;
}
function OnGUI () {
if (Network.isClient !isInstantiated)
if (GUI.Button(new Rect(20,Screen.height-60, 90, 20),"SpawnPlayer"))
{
networkView.RPC("SpawnPlayer", RPCMode.AllBuffered);
isInstantiated = true;
}
}
@RPC
function SpawnPlayer () {
if(networkView.group == 5){
Instantiate(playerPrefab, transform.position, transform.rotation);
}
else{
Debug.Log("not in the group");
}
}
function OnPlayerDisconnected (player : NetworkPlayer) {
Debug.Log("Cleaning up player " + player);
Network.RemoveRPCs(player, 5);
Network.DestroyPlayerObjects(player);
}
but this way it acts as local Instantiate - player1’s prefab is instantiated only on player1’s screen…
I don’t get the grouping thing right, do I… :? ?
can anyone please enlight me…?
thanks…