- Home /
Question by
hubbyo9 · Aug 29, 2013 at 08:01 PM ·
javascriptinstantiatenetwork
Network Connection + Instantiation errors
I have 2 scripts, the server script and the client script. They are both on an empty object called the Initializer. I toggled some stuff off for the client build and toggled them back on for the server which I am running in the Unity editor. The client apparently connects to the server but I cannot see the connections nor can I see the player object.
Client Script:
#pragma strict
var hostList : HostData[];
function JoinServer () {
Network.Connect("127.0.0.1", 25000);
}
function Update () {
}
function OnConnectedToServer(){
Debug.Log("Joined Server");
networkView.RPC("SpawnPlayer", RPCMode.AllBuffered);
}
Server Script:
#pragma strict
var IsServer : boolean = false;
var playerPrefab : GameObject;
function Start () {
if(IsServer == true){
StartServer();
}
playerPrefab = GameObject.Find("GameObject");
}
function Update () {
}
function StartServer () {
Network.InitializeSecurity();
var useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 25002, useNat);
}
function OnServerInitialized(){
Debug.Log("Server Initialized");
}
function SpawnPlayer(){
Network.Instantiate(playerPrefab, new Vector3(-111f, 10f, 55f), Quaternion.identity, 0);
}
function OnConnectedToServer(){
networkView.RPC("SpawnPlayer", RPCMode.AllBuffered);
}
I have gotten many headaches over this and I hope people here can figure out whats wrong. I am not that new to Unity but I have always had troubles with the multiplayer. Thank you in advance!
Comment
So does no one know what the problem is? I still can't figure it out!
Your answer
