1

すべてを接続するためにローカルの WAMP サーバーを使用しています。サーバーを起動してからクライアントに接続しても、エラーは発生しません。プレイヤーがスポーンするまではすべて問題なく動作しているようで、「SpawnObject for SkeletonPlayer(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without a active server.」と表示されます。何が起こっているかについてのアイデアはありますか?

void OnGUI()
{
if (isAtStartup)
    {
        GUI.Label(new Rect(2, 10, 150, 100), "Press S for server");
        GUI.Label(new Rect(2, 50, 150, 100), "Press R for registered servers");
        GUI.Label(new Rect(2, 90, 150, 100), "Press C for client");
    }
}

public void SetupServer()
{
    //connecting to my server
    NetworkServer.Listen(4444);
    isAtStartup = false;
    Debug.Log("Server Connected");
}

 public void SetupClient()
{
    ClientScene.RegisterPrefab(playerPrefab);

    myClient = new NetworkClient();

    myClient.RegisterHandler(MsgType.Connect, OnConnected);
    myClient.Connect("127.0.0.1", 4444);      

    isAtStartup = false;      
}

// Create a local client and connect to the local server
public void SetupLocalClient()
{
    myClient = ClientScene.ConnectLocalServer();
    myClient.RegisterHandler(MsgType.Connect, OnConnected);
    isAtStartup = false;
}

// client function
public void OnConnected(NetworkMessage netMsg)
{
    Debug.Log("Connected to server");
            GameObject player = (GameObject)Instantiate(playerPrefab, transform.position, transform.rotation);
            NetworkServer.Spawn(player);
    }
}
4

0 に答える 0