Search Unity

[Tutorial] Basic Multiplayer FPS Videos

Discussion in 'Community Learning & Teaching' started by Boomsma1995, Jul 3, 2012.

  1. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Hello, My name is Richard Boomsma. I am the lead programmer of Remixgames. Lately i got lots of request to do tutorials for an multiplayer fps. Well i thougt that is a great idea so here i am with my first tutorial video showing you guys how to make a basic multiplayer fps. All the Videos are shown in this post and Im dutch so if u noticed me talking rubish :D im sorry for that than.

    Enjoy.

    *** The youtube channel got hacked, The videos are not available anymore. The scripts are still available on http://pastebin.com/u/boomsma95. ***
     
    Last edited: Oct 26, 2013
  2. DrSega

    DrSega

    Joined:
    Mar 6, 2012
    Posts:
    157
    Very helpfull tutorials and are the most helpfull i have found, thanks :)
     
  3. tuliocll

    tuliocll

    Joined:
    Oct 24, 2011
    Posts:
    89
    Good!
     
  4. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thanks.
     
  5. [S]pace

    [S]pace

    Joined:
    Jul 7, 2012
    Posts:
    1
    Poderia postar os codigos no post?
    Could you post the codes in the post?
     
  6. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    I rather not, It defeats the purpose of learning it.
     
    Ronanelf likes this.
  7. Muuskii

    Muuskii

    Joined:
    Jul 7, 2012
    Posts:
    5
    Do you have something against copy pasting? Just because we typed it from your video doesn't mean we paid attention doing it :p

    Also not everyone has two monitors like me :D
     
  8. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    You got a point there but i just hate it that people just copy paste it without watching the video and go like "WTF this doesn't work you are crap" etc...

    P.S. my example was a bit :D:D.
     
  9. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    697
    I see many tutorials on FPS, Multiplayer, the problem for me is that they are all in C #.

    I hope the soon see on youtube in js.
     
  10. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    I could release a video for how to convert the scripts to javascript. But personally i think C# is a better and for more bigger than UnityScript and the fact that you have acces to .Net functions.
     
  11. marf

    marf

    Joined:
    Jul 20, 2011
    Posts:
    122
    Thank you very much for those tutorials, they are very good!
     
  12. DrSega

    DrSega

    Joined:
    Mar 6, 2012
    Posts:
    157
    You don't have to have two monitors. Just use half screen for the code and half for video.
     
  13. wana7262

    wana7262

    Joined:
    Jul 2, 2012
    Posts:
    95
    is it complete tutorial???
     
  14. waddlesticks

    waddlesticks

    Joined:
    Jan 25, 2013
    Posts:
    3
    Ignore anything below, realised that I had in the;
    void Client_RemovePlayer (NetworkPlayer view)
    was
    void Client_RemovePlayer(NetworkPlayer veiw)

    EDIT: I seem to be getting this error... (On the first tutorial around 23:43)
    Assets/Scripts/MultiplayerManager.cs(66,49): error CS0103: The name `view' does not exist in the current context




    Didn't get to watch it due to internet being annoying...
    When you create scripts in the videos, do you by any chance comment on them and state what they do and so forth for future reference?

    :)
     
    Last edited: Jan 25, 2013
  15. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    Thank you.
     
  16. Kaji-Atsushi

    Kaji-Atsushi

    Joined:
    Oct 6, 2012
    Posts:
    234
    Looking forward to learning from your tutorials thanks!
     
  17. JscriptFless

    JscriptFless

    Joined:
    Jan 8, 2013
    Posts:
    49
    :cool:Thankyou!!!!!!!!!!!!! ;) :) :D
     
  18. Leichenzug

    Leichenzug

    Joined:
    Feb 28, 2013
    Posts:
    5
    Hi, i follow ure tutorial series but now i have a major problem... i have an error that i dont get fixed, i tried it for 3 days now...
    The Error is:

    NullReferenceException: Object reference not set to an instance of an object
    MultiplayerManager.Client_SpawnPlayer (NetworkPlayer player, Vector3 position, Quaternion rotation) (at Assets/Scripts/MultiplayerManager.cs:175)
    UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
    MultiplayerManager:Server_SpawnPlayer(NetworkPlayer) (at Assets/Scripts/MultiplayerManager.cs:164)
    MultiplayerManager:SpawnMenu() (at Assets/Scripts/MultiplayerManager.cs:221)
    MultiplayerManager:OnGUI() (at Assets/Scripts/MultiplayerManager.cs:156)

    The MultiplayerManager Script is:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class MultiplayerManager : MonoBehaviour
    6. {
    7.     public static MultiplayerManager instance;
    8.    
    9.     public GameObject PlayerManagerPrefab;
    10.    
    11.     public string PlayerName;
    12.     private string MatchName = "";
    13.     private string MatchPassword = "";
    14.     private int MatchMaxUsers = 32;
    15.    
    16.     public List<MPPlayer> PlayerList = new List<MPPlayer>();
    17.     public List<MapSetting> MapList = new List<MapSetting>();
    18.    
    19.     public MapSetting CurrentMap = null;
    20.     public int oldprefix;
    21.     public bool IsMatchStarted = false;
    22.    
    23.     //General Multiplayer Modes
    24.     public bool MatchLoaded;
    25.     public MPPlayer MyPlayer;
    26.     public GameObject[] Spawnpoints;
    27.    
    28.    
    29.     void Start () {
    30.         instance = this;
    31.         PlayerName = PlayerPrefs.GetString("PlayerName");
    32.         CurrentMap = MapList[0];
    33.         DontDestroyOnLoad(gameObject);
    34.     }
    35.    
    36.     void FixedUpdate()
    37.     {
    38.        
    39.     }
    40.    
    41.     public void StartServer(string servername, string serverpassword, int maxuser)
    42.     {
    43.         MatchName = servername;
    44.         MatchPassword = serverpassword;
    45.         MatchMaxUsers = maxuser;
    46.         Network.InitializeServer(MatchMaxUsers, 2550, false);
    47.         MasterServer.RegisterHost("DeathMatch", MatchName, "");
    48. //      Network.InitializeSecurity();
    49.     }
    50.    
    51.     void OnServerInitialized()
    52.     {
    53.         Server_PlayerJoinRequest(PlayerName, Network.player);
    54.     }
    55.    
    56.     void OnConnectedToServer()
    57.     {
    58.         networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
    59.     }
    60.    
    61.     void OnPlayerDisconnected(NetworkPlayer id)
    62.     {
    63.         networkView.RPC("Client_RemovePlayer", RPCMode.All, id);
    64.     }
    65.    
    66.     void OnPlayerConnected(NetworkPlayer player)
    67.     {
    68.         foreach(MPPlayer pl in PlayerList)
    69.         {
    70.             networkView.RPC("Client_AddPlayerToList", player, pl.Playername, pl.PlayerNetwork);
    71.         }
    72.        
    73.         networkView.RPC("Client_GetMultiplayerMatchSettings", player, CurrentMap.MapName, "", "");
    74.        
    75.     }
    76.    
    77.     void OnDisconnectFromServer()
    78.     {
    79.         PlayerList.Clear();
    80.     }
    81.    
    82.     [RPC]
    83.     void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
    84.     {
    85.         networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
    86.     }
    87.    
    88.     [RPC]
    89.     void Client_AddPlayerToList(string playername, NetworkPlayer view)
    90.     {
    91.         MPPlayer tempplayer = new MPPlayer();
    92.         tempplayer.Playername = playername;
    93.         tempplayer.PlayerNetwork = view;
    94.         PlayerList.Add(tempplayer);
    95.         if(Network.player == view)
    96.         {
    97.             MyPlayer = tempplayer;
    98.             GameObject play = Network.Instantiate(PlayerManagerPrefab, Vector3.zero, Quaternion.identity, 5) as GameObject;
    99. //          play.GetComponent<PlayerManager>().thisplayer = MyPlayer;
    100.         }
    101.     }
    102.    
    103.     [RPC]
    104.     void Client_RemovePlayer(NetworkPlayer view)
    105.     {
    106.         MPPlayer temppl = null;
    107.        
    108.         foreach(MPPlayer pl in PlayerList)
    109.         {
    110.             if (pl.PlayerNetwork == view)
    111.             {
    112.                 temppl = pl;
    113.             }
    114.         }
    115.        
    116.         if (temppl != null)
    117.         {
    118.             PlayerList.Remove(temppl);
    119.         }
    120.    
    121.     }
    122.    
    123.     [RPC]
    124.     void Client_GetMultiplayerMatchSettings(string map, string mode, string others)
    125.     {
    126.         CurrentMap = GetMap(map);  
    127.     }
    128.    
    129.     public MapSetting GetMap(string name)
    130.     {
    131.         MapSetting get = null;
    132.        
    133.         foreach(MapSetting st in MapList)
    134.         {
    135.             if(st.MapName == name)
    136.             {
    137.                 get = st;
    138.                 break;
    139.             }
    140.         }
    141.        
    142.         return get;
    143.     }
    144.    
    145.     [RPC]
    146.     void Client_LoadMultiplayerMap(string map, int prefix)
    147.     {
    148. //      Network.SetLevelPrefix(prefix);
    149.         Application.LoadLevel(map);
    150.     }
    151.    
    152.     void OnGUI()
    153.     {
    154.         if(!MyPlayer.PlayerIsAlive  IsMatchStarted)
    155.         {
    156.             SpawnMenu();
    157.         }
    158.     }
    159.    
    160.     [RPC]
    161.     void Server_SpawnPlayer(NetworkPlayer player)
    162.     {
    163.         int numberspawn = Random.Range(0, Spawnpoints.Length - 1);
    164.         networkView.RPC("Client_SpawnPlayer", RPCMode.All, player, Spawnpoints[numberspawn].transform.position + new Vector3(0,2,0), Spawnpoints[numberspawn].transform.rotation);
    165.     }
    166.    
    167.     [RPC]
    168.     void Client_SpawnPlayer(NetworkPlayer player, Vector3 position, Quaternion rotation)
    169.     {
    170.         MultiplayerManager.GetMPPlayer(player).PlayerIsAlive = true;
    171.         MultiplayerManager.GetMPPlayer(player).PlayerHealth = 100;
    172.        
    173.         if(player == MyPlayer.PlayerNetwork)
    174.         {
    175.             MyPlayer.PlayerManager.ControllerTransform.position = position;
    176.             MyPlayer.PlayerManager.ControllerTransform.rotation = rotation;
    177.             MyPlayer.PlayerManager.networkView.RPC("Client_PlayerAlive", RPCMode.All);
    178.         }
    179.         else
    180.         {
    181.            
    182.         }
    183.     }
    184.    
    185.     void OnLevelWasLoaded()
    186.     {
    187.         if(Application.loadedLevelName == CurrentMap.MapLoadName)
    188.         {
    189.             MatchLoaded = true;
    190.             Spawnpoints = GameObject.FindGameObjectsWithTag("spawnpoint");
    191.             networkView.RPC ("Client_ServerLoaded", RPCMode.AllBuffered, IsMatchStarted);
    192.         }
    193.     }
    194.    
    195.     [RPC]
    196.     void Client_ServerLoaded(bool started)
    197.     {
    198.         MatchLoaded = true;
    199.         IsMatchStarted = started;
    200.     }
    201.    
    202.     public static MPPlayer GetMPPlayer(NetworkPlayer player)
    203.     {
    204.         foreach(MPPlayer play in MultiplayerManager.instance.PlayerList)
    205.         {
    206.             if(play.PlayerNetwork == player)
    207.             {
    208.                 return play;
    209.             }
    210.         }
    211.         return null;
    212.     }
    213.    
    214.     //Deathmatch
    215.        
    216.     void SpawnMenu()
    217.     {
    218.         if(GUI.Button(new Rect(5, Screen.height - 40, 250, 35 ), "Spawn"))
    219.         {
    220.             if(Network.isServer)
    221.                 Server_SpawnPlayer(Network.player);
    222.             else
    223.                 networkView.RPC("Server_SpawnPlayer", RPCMode.Server, Network.player);
    224.         }
    225.     }
    226. }
    227.  
    228. [System.Serializable]
    229. public class MPPlayer
    230. {
    231.     public string Playername = "";
    232.     public NetworkPlayer PlayerNetwork;
    233.     public PlayerManager PlayerManager;
    234.     public int PlayerHealth = 100;
    235.     public bool PlayerIsAlive;
    236.     public int PlayerKills;
    237.     public int PlayerDeaths;
    238. }
    239.  
    240. [System.Serializable]
    241. public class MapSetting
    242. {
    243.     public string MapName;
    244.     public string MapLoadName;
    245.     public Texture MapLoadTexture;
    246. }
    Please help me to find the mistake... also my playermanager prefab doesnt get attached in playmode...

    Many thanks for helping me out.
    greetings Leiche
     
  19. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    Hello,

    What do you mean with that your playermanager prefab doesn't get attached cause this is a must to make it work.
     
  20. Leichenzug

    Leichenzug

    Joined:
    Feb 28, 2013
    Posts:
    5
    nevermind i began the tut again :) wasted enough time to fix that error...
     
  21. yuhonglei

    yuhonglei

    Joined:
    Feb 26, 2013
    Posts:
    17
    Hi,bro
    I'm studying the #1,about MenuManger.cs

    I put the script into the camera and run, but no effect,could you help me? I'm a rookie.....

    I wrote the following script

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MenuManger : MonoBehaviour {
    5.    
    6.     public string CurrentMenu;
    7.  
    8.     public string MatchName = "";
    9.     public string MatchPassword = "";
    10.     public int MatchMaxPlayers = 32;
    11.  
    12.     void Start()
    13.     {
    14.         CurrentMenu = "Main";
    15.     }
    16.  
    17.     void OnGui()
    18.     {
    19.         if (CurrentMenu == "Main")
    20.         Menu_Main();
    21.         if (CurrentMenu == "Lobby")
    22.         Menu_Lobby();
    23.         if (CurrentMenu == "Host")
    24.         Menu_HostGame();
    25.  
    26.     }
    27.     public void NavigateTo(string nextmenu)
    28.     {
    29.         CurrentMenu = nextmenu;
    30.     }
    31.  
    32.     private void Menu_Main()
    33.     {
    34.         if (GUI.Button(new Rect(10,10,200,50),"Host Game"))
    35.         {
    36.             NavigateTo("Host");
    37.         }
    38.  
    39.     }
    40.  
    41.     private void Menu_HostGame()
    42.     {
    43.         //Buttons Host Game
    44.         if (GUI.Button(new Rect(10,10,200,50),"Back"))
    45.         {
    46.             NavigateTo("Main");
    47.  
    48.         }
    49.  
    50.         if (GUI.Button(new Rect(10,60,200,53),"Start Server"))
    51.         {
    52.  
    53.         }
    54.         GUI.Label(new Rect(220,10,130,30),"Match Name");
    55.         MatchName = GUI.TextField(new Rect(400,10,200,30),MatchName);
    56.  
    57.         GUI.Label(new Rect(220,50,130,30),"Match Password");
    58.         MatchPassword = GUI.PasswordField(new Rect(400,50,200,30),MatchPassword,'*');
    59.  
    60.         GUI.Label(new Rect(220,90,130,30),"Match Max Players");
    61.         GUI.Label(new Rect(400,90,200,30),MatchMaxPlayers.ToString());
    62.         MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers,8,32);
    63.  
    64.         if (GUI.Button(new Rect(425,90,25,30),"+"))
    65.             MatchMaxPlayers += 2;
    66.         if (GUI.Button(new Rect(450,90,25,30),"-"))
    67.             MatchMaxPlayers -= 2;
    68.  
    69.         }
    70.  
    71.    
    72.  
    73.  
    74.     private void Menu_Lobby()
    75.     {
    76.  
    77.     }
    78.  
    79.  
    80. }
    81.  
    $bbbb.jpg
     
    Last edited: Mar 11, 2013
  22. Leichenzug

    Leichenzug

    Joined:
    Feb 28, 2013
    Posts:
    5
    @yuhonglei:

    rename your "void OnGui" to "void OnGUI" on Line 17. I think thats all :)
     
  23. oooiiio@net.hr

    oooiiio@net.hr

    Joined:
    Feb 23, 2013
    Posts:
    1
    Hi Richard, hmm i have a problem with the scripts on 2nd vid and if you can look it for you it is 5 sec and bom you find it but me -.- yea i looked your video like 3 times and can find reson
    here is the errors:
    Assets/Scripts/MultiplayerManager.cs(107,17): error CS0131: The left-hand side of an assignment must be a variable, a property or an indexer
    Assets/Scripts/MultiplayerManager.cs(112,33): error CS0103: The name `get' does not exist in the current context
    Assets/Scripts/MultiplayerManager.cs(116,24): error CS0103: The name `get' does not exist in the current context

    now here is the scripts
    MultiplayerManager
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5.     public class MultiplayerManager : MonoBehaviour
    6. {
    7.     public static MultiplayerManager instance;
    8.     public string playername;
    9.    
    10.     private string MatchName = "";
    11.     private string MatchPassword = "";
    12.     private int MatchMaxUsers = 16;
    13.    
    14.     public List<MPPlayer> Playerlist = new List<MPPlayer>();
    15.     public List<MapSetting> Maplist = new List<MapSetting>();
    16.     public MapSetting CurrentMap = null;
    17.    
    18.     public int oldprefix;
    19.     public bool IsMatchStarted = false;
    20.    
    21.     void Start()
    22.         {
    23.             instance = this;
    24.             playername = PlayerPrefs.GetString("PlayerName");
    25.             CurrentMap = Maplist[0];
    26.         }
    27.    
    28.     void FixedUpdate()
    29.     {
    30.         instance = this;
    31.     }
    32.    
    33.     public void StartServer(string servername, string serverpassword, int maxusers)
    34.     {
    35.         MatchName = servername;
    36.         MatchPassword = serverpassword;
    37.         MatchMaxUsers = maxusers;
    38.         Network.InitializeServer(MatchMaxUsers, 2550, false);
    39.         MasterServer.RegisterHost("BloodyWar", MatchName, "");
    40.         //Network.InitializeSecurity();
    41.     }
    42.    
    43.     void OnServerInitialized()
    44.     {
    45.         Server_PlayerJoinRequest(playername, Network.player);
    46.     }
    47.    
    48.     void OnConnectedToServer()
    49.     {
    50.         networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, playername, Network.player);
    51.     }
    52.    
    53.     void OnPlayerDisconnected(NetworkPlayer id)
    54.     {
    55.         networkView.RPC("Client_RemuvePlayer", RPCMode.All, id);
    56.     }
    57.    
    58.     void OnPlayerConnected(NetworkPlayer player)
    59.     {
    60.         foreach(MPPlayer pl in Playerlist)
    61.         {
    62.             networkView.RPC("Client_AddPlayerToList", player, pl.PlayerName, pl.PlayerNetwork);
    63.         }
    64.         networkView.RPC("Client_GetMultiplayerMatchSettings", player, CurrentMap.MapName, "", "");
    65.     }
    66.  
    67.     [RPC]
    68.     void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
    69.     {
    70.         networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
    71.     }
    72.    
    73.     [RPC]
    74.     void Client_AddPlayerToList(string playername, NetworkPlayer view)
    75.         {
    76.         MPPlayer tempplayer = new MPPlayer();
    77.         tempplayer.PlayerName = playername;
    78.         tempplayer.PlayerNetwork = view;
    79.         Playerlist.Add(tempplayer);
    80.         }
    81.    
    82.     [RPC]
    83.     void Client_RemuvePlayer(NetworkPlayer view)
    84.     {
    85.         MPPlayer temppl = null;
    86.         foreach(MPPlayer pl in Playerlist)
    87.         {
    88.             if (pl.PlayerNetwork == view)
    89.             {
    90.                 temppl = pl;
    91.             }
    92.             if (temppl != null)
    93.             {
    94.                 Playerlist.Remove(temppl);
    95.             }
    96.         }
    97.     }
    98.    
    99.     [RPC]
    100.     void Client_GetMultiplayerMatchSettings(string map, string mode, string others)
    101.     {
    102.         CurrentMap = GetMap(map);
    103.     }
    104.    
    105.     public MapSetting GetMap(string name)
    106.     {
    107.         MapSetting = null;
    108.        
    109.         foreach(MapSetting st in Maplist)
    110.         {
    111.             if (st.MapName == name)
    112.                 get = st;
    113.                 break;
    114.         }
    115.        
    116.         return get;
    117.     }
    118.    
    119.     [RPC]
    120.     void Client_LoadMultiPlayerMap(string map, int prefix)
    121.     {
    122.         Network.SetLevelPrefix(prefix);
    123.         Application.LoadLevel(map);
    124.     }
    125. }
    126. [System.Serializable]
    127. public class MPPlayer
    128.     {
    129.     public string PlayerName = "";
    130.     public NetworkPlayer PlayerNetwork;
    131.     }
    132.  
    133. [System.Serializable]
    134. public class MapSetting
    135. {
    136.     public string MapName;
    137.     public string MapLoadName;
    138.     public Texture MapTexture;
    139. }
    and MenuManger
    Code (csharp):
    1.     using UnityEngine;
    2.     using System.Collections;
    3.      
    4.     public class MenuManger : MonoBehaviour
    5.     {
    6.         public MenuManger instance;
    7.        
    8.         public string CurrentMenu;
    9.         public string MatchName = "";
    10.         public string MatchPassword = "";
    11.        
    12.         public int MatchMaxPlayers = 32;
    13.        
    14.         private Vector2 ScrollLobby = Vector2.zero;
    15.  
    16.    
    17.         void Start()
    18.         {
    19.             instance = this;
    20.             CurrentMenu = "Main";
    21.         }
    22.    
    23.         void fixedupdate()
    24.         {
    25.         instance = this;
    26.         }
    27.      
    28.         void OnGUI()
    29.         {
    30.             if (CurrentMenu == "Main")
    31.             Menu_Main();
    32.             if (CurrentMenu == "Lobby")
    33.             Menu_Lobby();
    34.             if (CurrentMenu == "Host")
    35.             Menu_HostGame();
    36.             if (CurrentMenu == "ChoMap")
    37.             Menu_ChooseMap();
    38.         }
    39.        
    40.         public void NavigateTo(string nextmenu)
    41.         {
    42.             CurrentMenu = nextmenu;
    43.         }
    44.      
    45.         private void Menu_Main()
    46.         {
    47.             if (GUI.Button(new Rect(300,200,200,50),"Host Game"))
    48.             {
    49.                 NavigateTo("Host");
    50.             }
    51.             if (GUI.Button(new Rect(300,250,200,50),"Refresh"))
    52.             {
    53.                 MasterServer.RequestHostList("BloodyWar");
    54.             }
    55.             if (GUI.Button(new Rect(300,300,200,50),"Quit"))
    56.             {
    57.                 Application.Quit();
    58.             }
    59.        
    60.         GUI.Label(new Rect(525,210,200,50),"Player Name");
    61.            
    62.         MultiplayerManager.instance.playername = GUI.TextField(new Rect(630,205,200,30),MultiplayerManager.instance.playername);
    63.            
    64.         if (GUI.Button(new Rect(630,245,200,20),"Save Name"))
    65.             {
    66.                 PlayerPrefs.SetString("PlayerName", MultiplayerManager.instance.playername);
    67.             }
    68.         GUILayout.BeginArea(new Rect(Screen.width - 250,25,250, Screen.height),"Match List", "Box");
    69.         GUILayout.Space(20);
    70.                 foreach(HostData match in MasterServer.PollHostList())
    71.                 {
    72.                     GUILayout.BeginHorizontal("Box");
    73.                     GUILayout.Label(match.gameName);
    74.                    
    75.                     if (GUILayout.Button("connect"))
    76.                         {
    77.                             Network.Connect(match);
    78.                         }
    79.                     GUILayout.EndHorizontal();
    80.                 }
    81.        
    82.             GUILayout.EndArea();
    83.         }
    84.  
    85.         private void Menu_HostGame()
    86.         {
    87.             //Buttons Host Game
    88.             if (GUI.Button(new Rect(300,300,200,47),"Back"))
    89.             {
    90.                 NavigateTo("Main");
    91.                
    92.             }
    93.             if (GUI.Button(new Rect(300,200,200,50),"Start Server"))
    94.             {
    95.                 MultiplayerManager.instance.StartServer(MatchName, MatchPassword, MatchMaxPlayers);
    96.             }
    97.             if (GUI.Button(new Rect(300,250,200,50),"Choose Map"))
    98.             {
    99.                 NavigateTo("ChoMap");
    100.             }
    101.             GUI.Label(new Rect(525,210,200,50),"Match Name");
    102.             MatchName = GUI.TextField(new Rect(630,205,200,30),MatchName);
    103.      
    104.             GUI.Label(new Rect(525,260,200,50),"Match Password");
    105.             MatchPassword = GUI.PasswordField(new Rect(630,255,200,30),MatchPassword,'*');
    106.      
    107.             GUI.Label(new Rect(525,310,200,30),"Match Max Players");
    108.             GUI.Label(new Rect(710,305,200,30),MatchMaxPlayers.ToString());
    109.             MatchMaxPlayers = Mathf.Clamp(MatchMaxPlayers,4,16);
    110.      
    111.             if (GUI.Button(new Rect(730,305,25,30),"+"))
    112.                 MatchMaxPlayers += 2;
    113.             if (GUI.Button(new Rect(680,305,25,30),"-"))
    114.                 MatchMaxPlayers -= 2;
    115.        
    116.             GUI.Label(new Rect(630,205,200,30), MultiplayerManager.instance.CurrentMap.MapName);
    117.             }
    118.      
    119.         private void Menu_Lobby()
    120.         {
    121.             ScrollLobby = GUILayout.BeginScrollView(ScrollLobby, GUILayout.MaxWidth (200));
    122.            
    123.             foreach(MPPlayer pl in MultiplayerManager.instance.Playerlist)
    124.             {
    125.                 GUILayout.Box(pl.PlayerName);
    126.             }
    127.        
    128.             GUILayout.EndScrollView();
    129.        
    130.         GUI.Box(new Rect(525,210,200,50), MultiplayerManager.instance.CurrentMap.MapName);
    131.            
    132.         if (Network.isServer)
    133.         {
    134.             if(GUI.Button(new Rect(Screen.width - 200, Screen.height - 80 ,200,40),"Start Match"))
    135.             {
    136.                 MultiplayerManager.instance.networkView.RPC("Client_LoadMultiPlayerMap",RPCMode.All, MultiplayerManager.instance.CurrentMap.MapLoadName, MultiplayerManager.instance.oldprefix + 1);
    137.                 MultiplayerManager.instance.oldprefix += 1;
    138.                 MultiplayerManager.instance.IsMatchStarted = true;
    139.                 }
    140.             }
    141.         if(GUI.Button(new Rect(Screen.width - 200, Screen.height - 40 ,200,40),"Disconnect"))
    142.             {
    143.                 Network.Disconnect();
    144.             }
    145.         }
    146.    
    147.         private void Menu_ChooseMap()
    148.         {
    149.             if (GUI.Button(new Rect(300,200,200,50),"Back"))
    150.                 {
    151.                 NavigateTo("Host");
    152.                 }
    153.         GUI.Label(new Rect(525,210,200,50),"Choose Map");
    154.         GUILayout.BeginArea(new Rect(630,205,200,Screen.height));
    155.        
    156.         foreach (MapSetting map in MultiplayerManager.instance.Maplist)
    157.         {
    158.             if(GUILayout.Button(map.MapName))
    159.             {
    160.                 NavigateTo("Host");
    161.                 MultiplayerManager.instance.CurrentMap = map;
    162.             }
    163.         }
    164.        
    165.             GUILayout.EndArea();
    166.         }
    167.        
    168.         void OnServerInitialized()
    169.         {
    170.             NavigateTo("Lobby");       
    171.         }
    172.        
    173.         void OnConnectedToServer()
    174.         {
    175.             NavigateTo("Lobby");       
    176.         }
    177.      
    178.         void OnDisconnectedFromServer(NetworkDisconnection info)
    179.         {
    180.             NavigateTo ("Main");
    181.         }
    182.    
    183.    }
    tnx in front
    btw very good tutorials :D
     
  24. Daphoeno

    Daphoeno

    Joined:
    Oct 13, 2012
    Posts:
    2
    I have a problem. After tutorial #1 I ran and tested my server but when I tried to connect to the server it connected to the network but didn't go onto the list with the names.
    Before you say I have made the player settings so it is run in background.

    My menu script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class ServerMenu : MonoBehaviour
    6. {
    7.     public string CurrentMenu;
    8.    
    9.     public string ServerName = "Server";
    10.     public string ServerPass = "";
    11.     public int MaxPlayers = 32;
    12.    
    13.     private Vector2 ScrollLobby = Vector2.zero;
    14.    
    15.     void Start()
    16.     {
    17.         CurrentMenu = "Main";
    18.         ServerName = "Server" + Random.Range(000001,999999);
    19.     }
    20.    
    21.     void OnGUI ()
    22.     {
    23.         if(CurrentMenu == "Main")
    24.             Menu_Main();
    25.         if(CurrentMenu == "Lobby")
    26.             Menu_Lobby();
    27.         if(CurrentMenu == "Host")
    28.             Menu_HostGame();
    29.     }
    30.    
    31.     public void NavigateTo(string nextmenu)
    32.     {
    33.         CurrentMenu = nextmenu;
    34.     }
    35.    
    36.     private void Menu_Main()
    37.     {
    38.         if (GUI.Button(new Rect(10, 10, 200, 50), "Host Game"))
    39.         {
    40.             NavigateTo("Host");
    41.         }
    42.        
    43.         if (GUI.Button(new Rect(10, 70, 200, 50), "Refresh"))
    44.         {
    45.             MasterServer.RequestHostList("Server");
    46.         }
    47.        
    48.         GUI.Label(new Rect(220, 10, 200, 20), "Player Name");
    49.         MultiplayerManager.instance.PlayerName = GUI.TextField(new Rect(330, 10, 200, 20), MultiplayerManager.instance.PlayerName);
    50.        
    51.         if (GUI.Button(new Rect(220, 35, 310, 25), "Save Name"))
    52.         {
    53.             PlayerPrefs.SetString("PlayerName", MultiplayerManager.instance.PlayerName);
    54.         }
    55.        
    56.         GUILayout.BeginArea(new Rect(Screen.width - 400, 0, 400, Screen.height), "Server List", "Box");
    57.         GUILayout.Space (20);
    58.         foreach (HostData match in MasterServer.PollHostList())
    59.         {
    60.             GUILayout.BeginHorizontal("Box");
    61.            
    62.             GUILayout.Label(match.gameName);
    63.             if(GUILayout.Button("Connect"))
    64.             {
    65.                 Network.Connect(match);
    66.             }
    67.            
    68.             GUILayout.EndHorizontal();
    69.         }
    70.        
    71.         GUILayout.EndArea();
    72.     }
    73.    
    74.     private void Menu_HostGame()
    75.     {
    76.         if (GUI.Button(new Rect(10, 70, 200, 50), "Back"))
    77.         {
    78.             NavigateTo("Main");
    79.         }
    80.        
    81.         if (GUI.Button(new Rect(10, 10, 200, 50), "Start Server"))
    82.         {
    83.             MultiplayerManager.instance.StartServer(ServerName, ServerPass, MaxPlayers);
    84.         }
    85.        
    86.         GUI.Label(new Rect(220, 10, 200, 20), "Server Name");
    87.         ServerName = GUI.TextField(new Rect(330, 10, 200, 20), ServerName);
    88.        
    89.         GUI.Label(new Rect(220, 40, 200, 20), "Server Password");
    90.         ServerPass = GUI.PasswordField(new Rect(330, 40, 200, 20), ServerPass, '*');
    91.        
    92.         GUI.Label(new Rect(220, 70, 200, 20), "Max Players");
    93.         GUI.Label(new Rect(424, 70, 200, 20), MaxPlayers.ToString ());
    94.         MaxPlayers = Mathf.Clamp(MaxPlayers, 8, 32);
    95.        
    96.         if (GUI.Button(new Rect(450, 70, 80, 20), "+2"))
    97.             MaxPlayers += 2;
    98.         if (GUI.Button(new Rect(330, 70, 80, 20), "-2"))
    99.             MaxPlayers -= 2;
    100.     }
    101.    
    102.     private void Menu_Lobby()
    103.     {
    104.         ScrollLobby = GUILayout.BeginScrollView(ScrollLobby, GUILayout.MaxWidth(200));
    105.        
    106.         foreach(MPPlayer pl in MultiplayerManager.instance.PlayerList)
    107.         {
    108.             GUILayout.Box(pl.PlayerName);  
    109.         }
    110.        
    111.         GUILayout.EndScrollView();
    112.     }
    113.    
    114.     void OnServerInitialized()
    115.     {
    116.         NavigateTo("Lobby");
    117.     }
    118.    
    119.     void OnConnectToServer ()
    120.     {
    121.         NavigateTo("Lobby");
    122.     }
    123. }
    124.  
    my Multiplayer Manager script:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class MultiplayerManager : MonoBehaviour
    7. {
    8.     public static MultiplayerManager instance;
    9.    
    10.     public string PlayerName = "";
    11.    
    12.     private string ServerName = "";
    13.     private string ServerPass = "";
    14.     private int MaxPlayers = 32;
    15.    
    16.     public List<MPPlayer> PlayerList = new List<MPPlayer>();
    17.    
    18.     void Start()
    19.     {
    20.         instance = this;
    21.         PlayerName = PlayerPrefs.GetString("PlayerName");
    22.     }
    23.    
    24.     public void StartServer(string servername, string serverpassword, int maxusers)
    25.     {
    26.         ServerName = servername;
    27.         ServerPass = serverpassword;
    28.         MaxPlayers = maxusers;
    29.         Network.InitializeServer(MaxPlayers, 2550, false);
    30.         MasterServer.RegisterHost("Server", ServerName, "");
    31.         //Network.InitializeSecurity();
    32.     }
    33.    
    34.     void OnServerInitialized()
    35.     {
    36.         Server_PlayerJoinRequest(PlayerName, Network.player);
    37.     }
    38.    
    39.     void OnConnectToServer ()
    40.     {
    41.         networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, PlayerName, Network.player);
    42.     }
    43.    
    44.     void OnPlayerDisconnected (NetworkPlayer id)
    45.     {
    46.         networkView.RPC("Client_RemovePlayer", RPCMode.All, id);
    47.     }
    48.    
    49.     [RPC]
    50.     void Server_PlayerJoinRequest(string playername, NetworkPlayer view)
    51.     {
    52.         networkView.RPC("Client_AddPlayerToList", RPCMode.All, playername, view);
    53.     }
    54.    
    55.     [RPC]
    56.     void Client_AddPlayerToList(string playername, NetworkPlayer view)
    57.     {
    58.         MPPlayer tempplayer = new MPPlayer();
    59.         tempplayer.PlayerName = playername;
    60.         tempplayer.PlayerNetwork = view;
    61.         PlayerList.Add (tempplayer);
    62.     }
    63.    
    64.     [RPC]
    65.     void Client_RemovePlayer(NetworkPlayer view)
    66.     {
    67.         MPPlayer temppl = null;
    68.         foreach(MPPlayer pl in PlayerList)
    69.         {
    70.             if(pl.PlayerNetwork == view)
    71.             {
    72.                 temppl = pl;
    73.             }
    74.         }
    75.         if(temppl != null)
    76.         {
    77.             PlayerList.Remove (temppl);
    78.         }
    79.     }
    80. }
    81.  
    82. public class MPPlayer
    83. {
    84.     public string PlayerName = "";
    85.     public NetworkPlayer PlayerNetwork;
    86. }
    87.  
     
  25. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    You should change your OnConnectToServer to OnConnectedToServer. Then it should work.
     
  26. CantUnderstandJS

    CantUnderstandJS

    Joined:
    Jan 23, 2013
    Posts:
    19
    I receive two errors.

    I Can run game in network, but don't show lobby at the client and receive two erros in Unity Console:

    RPC call failed because the function 'Client_GetMultiplayerMatchSettings' does not exist in the any script attached to'Multiplayer Manager'
    UnityEngine.NetworkView:RPC(String, NetworkPlayer, Object[])
    MultiplayerManager:OnPlayerConnected(NetworkPlayer) (at Assets/Scripts/C#/MultiplayerManager.cs:67)


    RPC call failed because the function 'Client_PlayerJoinRequest' does not exist in the any script attached to'Multiplayer Manager'
    UnityEngine.NetworkView:RPC(String, RPCMode, Object[])
    MultiplayerManager:OnPlayerDisconnected(NetworkPlayer) (at Assets/Scripts/C#/MultiplayerManager.cs:57)


    Nice tutorials :)
     
    Last edited: Apr 19, 2013
  27. CantUnderstandJS

    CantUnderstandJS

    Joined:
    Jan 23, 2013
    Posts:
    19
    Solved. Two errors on these functions.
     
  28. H00DJAMBRA

    H00DJAMBRA

    Joined:
    Jul 7, 2013
    Posts:
    1
    I have error:
    NullReferenceException: Object reference not set to an instance of an object
    PlayerManager.Start () (at Assets/Scripts/C#/PlayerManager.cs:26)


    HELP ME PLEASE!
     
  29. MrMassively

    MrMassively

    Joined:
    Sep 4, 2013
    Posts:
    115
    hmmmm, where did they go??

    al video tuts are gone , what happened?
     
  30. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    The youtube channel got hacked and we lost all our videos. the scripts however are still available here. http://pastebin.com/u/boomsma95
     
  31. puran1313

    puran1313

    Joined:
    Apr 22, 2013
    Posts:
    2
    Will You Upload The Videos Again or Make New Ones, Or you wont do it?
    Anyways i am looking forward to your Tutorials :)
     
  32. Boomsma1995

    Boomsma1995

    Joined:
    Mar 21, 2011
    Posts:
    95
    At the moment im not planning on doing anything tutorial related. But I will probally think about doing it again in the near future.
     
  33. puran1313

    puran1313

    Joined:
    Apr 22, 2013
    Posts:
    2
  34. oliv2112

    oliv2112

    Joined:
    Sep 29, 2013
    Posts:
    1
    Could you by any chance give me a link to the demo scene you used for the tutorial ?
    I did only get to watch half of the tutorial so i aren´t abel to finish the project. If anyone could help me or send the tutorial project so i can se how it´s set up, it would be awesome I have already gotten the scripts but i dont know how to put them into the game.
    -Oliver
     
  35. reaperkan

    reaperkan

    Joined:
    Aug 5, 2013
    Posts:
    15
    Dude seriously i have no idea of what to do and where to attach these scripts coz your tutorials are down ;(
     
unityunity