I am trying to figure out how to make the server spawn a controllable player for both the player starting the server and the one connecting. Only the connecting player is able to recieve a player that they can walk around with. The person who starts the server doesn’t get a character to control and it never says “connected” in the debug but other players are still able to connect to my ip and port. Maybe someone can see if I’m doing anything wrong, or do I need to add something special to my player prefab? My player prefab is the only one with a network view.
#pragma strict
var playerSpawn : Transform;
var ipAddress : String = "127.0.0.1";
var port : int = 25000;
var maxConnections : int = 10;
function OnGUI () {
GUILayout.BeginHorizontal ();
ipAddress = GUILayout.TextField (ipAddress);
GUILayout.Label ("IP ADDRESS");
GUILayout.EndHorizontal ();
GUILayout.BeginHorizontal ();
var tempPort : String;
tempPort = GUILayout.TextField (port.ToString());
port = parseInt(tempPort);
GUILayout.Label ("PORT");
GUILayout.EndHorizontal();
if(GUILayout.Button ("CONNECT")) {
print("connecting... ");
Network.Connect (ipAddress, port);
}
if(GUILayout.Button ("START SERVER")) {
print("starting server on " + ipAddress + ":" + port);
Network.InitializeServer (maxConnections, port, false);
}
}
function OnServerInitialize () {
spawnPlayer();
}
function OnConnectedToServer () {
spawnPlayer();
}
function spawnPlayer () {
Network.Instantiate(playerSpawn,transform.position,transform.rotation,0);
}
function OnPlayerDisconnect (playerSpawn:NetworkPlayer) {
Network.RemoveRPCs(playerSpawn);
Network.DestroyPlayerObjects(playerSpawn);
}
function OnDisconnectedFromServer(info:NetworkDisconnection) {
Network.RemoveRPCs(Network.player);
Network.DestroyPlayerObjects(Network.player);
Application.LoadLevel(Application.loadedLevel);
}