I’m having huge issues with instantiating players (using the first person controller).
When ever a server is initialized or someone connects to the server, the spawnpoint in the level has a script with a function that is called that does this:
function OnNetworkLoadedLevel ()
{
Network.Instantiate(players, transform.position, transform.rotation, 0);
}
With players being the first person controller prefab.
Couple issues with this is that when someone connects, on the server the prefab is instantiated but control and camera view is switched to this prefab and the one instantiated by the server on initialization just sits there.
On the screen of the connecting player, they are just alone as if it were single player.
How do I make it so that the first person controllers instantiated by the server and client are controlled by who spawned them and how do I make it so the client can see the server’s player?
My network script :
var remoteIP = “127.0.0.1”;
var remotePort = 25000;
var listenPort = 25000;
function OnGUI ()
{
if (Network.peerType == NetworkPeerType.Disconnected)
{
if (GUI.Button (new Rect(10,10,100,30),"Connect"))
{
// Connecting to the server
Network.Connect(remoteIP, remotePort);
}
if (GUI.Button (new Rect(10,50,100,30),"Start Server"))
{
// Creating server
Network.InitializeServer(32, listenPort, true);
// Notify our objects that the level and the network is ready
for (var go : GameObject in FindObjectsOfType(GameObject))
{
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
// Fields to insert ip address and port
remoteIP = GUI.TextField(new Rect(120,10,100,20), remoteIP);
remotePort = parseInt (GUI.TextField(new Rect(230,10,40,20), remotePort.ToString()));
}
else
{
if (GUI.Button (new Rect(10,10,100,50),"Disconnect"))
{
// Disconnect from the server
Network.Disconnect(200);
}
}
}
function OnConnectedToServer ()
{
// Notify our objects that the level and the network are ready
for (var go : GameObject in FindObjectsOfType(GameObject))
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}