- Home /
[Solved] Unet problem. The client always close when the connection is made with the host
So, this is the problem. I dont have a idea why this happen, and on the editor only this appears:
And this is the code that I'm using:
#pragma strict
import UnityEngine.Networking;
import UnityEngine.UI;
class NetworkManager_Custom extends NetworkManager
{
function IniciarServer()
{
definirPorta();
NetworkManager.singleton.StartHost();
}
function EntrarNoJogo() //ipe : String, port : int
{
definirIP();
definirPorta();
NetworkManager.singleton.StartClient();
}
function definirPorta()
{
NetworkManager.singleton.networkPort = 7777;
}
function definirIP()
{
NetworkManager.singleton.networkAddress = "localhost";
}
}
I found the problem, and, at least for me, it wasnt on the connection script, but on one of the players scripts. This was the script with problem.
#pragma strict
import UnityEngine.Networking;
var localDaArma : Transform;
@SyncVar
var armamento : Armamento;
class Armamento
{
var municaoTotal : int[];
var municaoPente : int[];
var armas : GameObject[];
var ultimaArma : GameObject;
}
function Awake()
{
//if
}
function Start ()
{
}
function Update ()
{
if(Input.GetAxis("Arma 1"))
MudarDeArma(1);
if(Input.GetAxis("Arma 2"))
MudarDeArma(2);
}
function MudarDeArma(arma : int)
{
}
It is a script to manage the weaponry of the player, that still to be done, but this isnt the problem. The problem was that I was trying to sync a var that was actually a constructor of a class, instead of the SyncListStruc, so, every time that the player spawn, with the script loaded, the client closes. I dont really know why this happens, but I changed that part for local management(just took off the @Syncvar attribute) and since then, the client works normally.
I have exactely the same problem and the same error (but with C#). - have you find a solution ?