hello, I was following [this][1] tutorial to create a multiplayer game. everything else works fine exept joining the server, here is the code:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour {
public string uniqueGameName;
public int playerCount;
private HostData[] hostList;
public GameObject playerPrefab;
public Transform[] spawnPoint = new Transform[2];
void StartServer ()
{
Network.InitializeServer(4, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(uniqueGameName, "MyGame");
}
void OnServerInitialized ()
{
Debug.Log("Server Initialized");
SpawnPlayer();
}
void OnConnectedToServer()
{
SpawnPlayer();
print("connected");
}
void RefreshHostList ()
{
MasterServer.RequestHostList(uniqueGameName);
}
void JoinServer (HostData myHostData)
{
Network.Connect(myHostData);
}
void OnMasterServerEvent (MasterServerEvent msEvent)
{
if (msEvent == MasterServerEvent.HostListReceived)
hostList = MasterServer.PollHostList();
}
void SpawnPlayer ()
{
Network.Instantiate(playerPrefab, spawnPoint[0].position, Quaternion.identity, 0);
}
void OnPlayerConnected()
{
playerCount++;
print ("PlayerConnected");
}
void OnGUI ()
{
if (!Network.isClient && !Network.isServer)
{
if (GUI.Button(new Rect(20, 20, 100, 20), "Start Server")) StartServer();
if (GUI.Button(new Rect(20, 45, 100, 20), "Refresh")) RefreshHostList();
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(125, 20 + (45 * i), 100, 20), hostList_.gameName)) JoinServer(hostList*);*_
* }*
* }*
* }*
* }*
}
I`ve looked over it a million times but I cant find what is wrong. I tied initializing the game on a stand alone to check for connection error messages in the unity edit, and tho the game does appear on the list there is no message nor does the player spawn. Im almost sure it something stupid but I cant find it. pls tell me any theorys you have on what it could be. Thank you.
_*[1]: http://www.paladinstudios.com/2013/07/10/how-to-create-an-online-multiplayer-game-with-unity/*_