Multiplayer Lobby script problem

Hello guys today i continue my FPS project, but 1. im making lobby, or multiplayer system. i have problems in part when i “start” server it wont show me the number of player ill give you all my scripts to check.

P.S. i didn’t get error

  1. Script
using UnityEngine;

using System.Collections;

 

public class MenuManager : MonoBehaviour {

 

    public string CurrentMenu;

    

    public string MatchName = "";

    public string MatchPassword = "";

    public int MatchMaxPlayers = 32;

    

    private Vector2 ScrollLobby = Vector2.zero;

    

    void Start()

    {

       CurrentMenu = "Main";

        MatchName = "Welcome" + Random.Range(0, 5000);

    }

 

    void OnGUI()

    {

        if(CurrentMenu == "Main")

            Menu_Main();

        if(CurrentMenu == "Lobby")

            Menu_Lobby();

        if(CurrentMenu == "Host")

            Menu_HostGame();

    }

    

    public void NavigateTo(string nextmenu)

    {

        CurrentMenu = nextmenu; 

    }

    

    private void Menu_Main()

    {

        if(GUI.Button(new Rect(10, 10, 200, 50), "Host Game"))

        {

           NavigateTo("Host");

        }

        GUI.Label(new Rect(220, 10, 130, 50), "Player Name");

        MultiplayerManager.instance.PlayerName = GUI.TextField(new Rect(350, 10, 150, 30), MultiplayerManager.instance.PlayerName);

        if(GUI.Button(new Rect(510, 10, 100, 30), "Save Name"))

        {

           PlayerPrefs.SetString("PlayerName", MultiplayerManager.instance.PlayerName);

        }

        }

    

    private void Menu_HostGame()

    {

        //Buttons Host Game

        if(GUI.Button(new Rect(10, 10, 200, 50), "Back"))

            

        {

            NavigateTo("Main");

        }

        

        if(GUI.Button(new Rect(10, 60, 200, 50), "Start Server"))

        {

            MultiplayerManager.instance.StartServer(MatchName, MatchPassword, MatchMaxPlayers);

        }

 

        GUI.Label(new Rect(220, 10, 130, 50), "Match Name");

        MatchName = GUI.TextField(new Rect(400, 10, 200, 30), MatchName);

        

        GUI.Label(new Rect(220, 50, 130, 50), "Match Password");

        MatchPassword = GUI.PasswordField(new Rect(400, 50, 200, 30), MatchPassword, '*');

        

        GUI.Label(new Rect(220, 90, 130, 50), "Match Max Players");

        GUI.Label(new Rect(400, 90, 200, 30), MatchMaxPlayers.ToString ());

        MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers, 8, 32);

        

        if(GUI.Button(new Rect(425, 90, 25, 30), "+"))

            MatchMaxPlayers += 2;

        if(GUI.Button(new Rect(450, 90, 25, 30), "-"))

            MatchMaxPlayers -= 2;

        

    }

    

    private void Menu_Lobby()

    {

         ScrollLobby = GUILayout.BeginScrollView(ScrollLobby, GUILayout.MaxWidth(200));

 

        foreach (MPPlayer pl in MultiplayerManager.instance.PlayerList)

        {

            GUILayout.Box(pl.PlayerName);   

        }

        

        

        GUILayout.EndScrollView();

    }

        void OnServerInitialize()

    {

        NavigateTo("Lobby");

    }

    void OnConnectedToServer()

    {

        NavigateTo("Lobby");

    }

    

}
  1. Scipt
using UnityEngine;

using System.Collections;

using System.Collections.Generic;

 

 

 

public class MultiplayerManager : MonoBehaviour 

    {

    public static MultiplayerManager instance;

    

    public string PlayerName;

    

    private string MatchName = "";

    private string MatchPassword = "";

    private int MatchMaxUsers = 32;

    

    public List<MPPlayer> PlayerList = new List<MPPlayer>();

    

    void Start()

    {

        instance = this;

        PlayerName = PlayerPrefs.GetString("Player Name");

    }

    

    public void StartServer(string servername, string serverpassword, int maxusers)

        

    {

        MatchName=servername;

        MatchPassword=serverpassword;

        MatchMaxUsers=maxusers;

        Network.InitializeServer(MatchMaxUsers,2550,false);

        //Network.InitializeSecurity();

        MasterServer.RegisterHost("DeathMatch",MatchName,"");

    

    }

    

    void OnServerInitialize()

    {

        Server_PlayerJoinRequest(PlayerName, Network.player);

    }

    void OnConnectedToServer()

    {

        networkView.RPC ("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);

    }

    void OnPlayerDisconneceted(NetworkPlayer id)

    {

        networkView.RPC ("Client_RemovePlayer", RPCMode.All, id);

    }

    [RPC]

    void Server_PlayerJoinRequest(string playername, NetworkPlayer view)

    {

       networkView.RPC ("Client_AddPlayerToList", RPCMode.All, playername, view);

    }

    [RPC]

    void Client_AddPlayerToList(string playername, NetworkPlayer view)

    {

        MPPlayer tempplayer = new MPPlayer();

        tempplayer.PlayerName = playername;

        tempplayer.PlayerNetwork = view;

        PlayerList.Add(tempplayer);

    }

    [RPC]

    void Client_RemovePlayer(NetworkPlayer view)

    {

        MPPlayer temppl = null;

        foreach(MPPlayer pl in PlayerList) 

    {

        if (pl.PlayerNetwork == view)

            {

            temppl = pl;

    

            }

        }

        if (temppl != null)

        {

        PlayerList.Remove(temppl);

      }

   }

}

 

public class MPPlayer

{

    public string PlayerName = "";

    public NetworkPlayer PlayerNetwork;

}

Anyone ?

Hi buddy,

I dont see the bug in your code. Perhaps you missed to attach it to the Game Object with the NetworkId Component described on the channel where you got that script from.

I know the code because I took the same tutorial and scripted it into JavaScript instead of C#.

If you dont know what tutorial Im talking about, please use this link: https://www.youtube.com/watch?v=m-iEOIXT19k&list=PLC90282759FD90F77

Best luck in your endevour!

But How ?
How Did He Change it into a Java Script can u make it a Script Of Java ?