Search Unity

RPC's not working

Discussion in 'Scripting' started by Stefan-Weegink, Sep 10, 2015.

  1. Stefan-Weegink

    Stefan-Weegink

    Joined:
    Feb 4, 2015
    Posts:
    40
    Hey I have been making this network script for my game and I recently update it to unity 5.2 but it now says the rpc's are deprecated. I search up and I saw you had to use the cloud to setup the network but you only have a maximum of 100 player, why? I am getting of topic but does this basicly means I have done all my work for nothing because I can't call the rpc's anymore. Thanks for helping

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class NetworkManage : MonoBehaviour {
    6.  
    7.     public string PlayerName;
    8.     public string MatchName;
    9.     public static NetworkManage Instance;
    10.  
    11.     public List<Player> PlayerList = new List<Player>();
    12.     public Player MyPlayer;
    13.     public GameObject SpawnPlayer;
    14.     public bool MatchStarted;
    15.     //public List<Transform> SpawnPoints = new List<Transform>();
    16.     //public GameObject[]SpawnPoints;
    17.     //public bool MatchLoaded;
    18.  
    19.     // Use this for initialization
    20.     void Start () {
    21.         Instance = this;
    22.         DontDestroyOnLoad (gameObject);
    23.    
    24.     }
    25.    
    26.     // Update is called once per frame
    27.     void Update () {
    28.         PlayerName = PlayerPrefs.GetString ("PlayerName");
    29.    
    30.     }
    31.  
    32.     public void StartServer(string ServerName, int MaxPlayers){
    33.         Network.InitializeSecurity();
    34.         Network.InitializeServer(MaxPlayers, 25565, true);
    35.         MasterServer.RegisterHost ("TEF",ServerName,"");
    36.  
    37.         Debug.Log ("Started Server");
    38.  
    39.     }
    40.     void OnPlayerConnected(NetworkPlayer id)
    41.     {
    42.         //networkView.RPC ("Server_PlayerJoined", RPCMode.Server, PlayerName, id);
    43.         if (Network.peerType == NetworkPeerType.Server) {
    44.             foreach (Player pl in PlayerList) {
    45.                 GetComponent<NetworkView>().RPC("Client_PlayerJoined", id, pl.PlayerName, pl.OnlinePlayer);
    46.             }
    47.         }
    48.     }
    49.     void OnServerInitialized()
    50.     {
    51.         Server_PlayerJoined(PlayerName, Network.player);
    52.     }
    53.     void OnConnectedToServer()
    54.     {
    55.         GetComponent<NetworkView>().RPC("Server_PlayerJoined", RPCMode.Server, PlayerName, Network.player);
    56.     }
    57.     void OnPlayerDisconnected(NetworkPlayer id)
    58.     {
    59.         Debug.Log("A player is leaving");
    60.         GetComponent<NetworkView>().RPC("RemovePlayer", RPCMode.All, id);
    61.         Network.Destroy (GetPlayer (id).Manager.gameObject);
    62.         Network.RemoveRPCs(id);
    63.         Debug.Log ("A player left");
    64.     }
    65.     void OnDisconnectedFromServer(NetworkDisconnection info)
    66.     {
    67.         Debug.Log ("You are leaving");
    68.         PlayerList.Clear();
    69.         Application.LoadLevel(0);
    70.         Debug.Log ("You left");
    71.     }
    72.     [RPC]
    73.     public void Server_PlayerJoined(string Username,NetworkPlayer id)
    74.     {
    75.         GetComponent<NetworkView>().RPC ("Client_PlayerJoined", RPCMode.All,Username, id);
    76.     }
    77.     [RPC]
    78.     public void Client_PlayerJoined(string Username, NetworkPlayer id)
    79.     {
    80.         Player temp = new Player();
    81.         temp.PlayerName = Username;
    82.         temp.OnlinePlayer = id;
    83.         PlayerList.Add(temp);
    84.         if (Network.player == id)
    85.         {
    86.             MyPlayer = temp;
    87.             GameObject LastPlayer = Network.Instantiate(SpawnPlayer, Vector3.zero, Quaternion.identity, 0) as GameObject;
    88.             //temp.Manager = LastPlayer.GetComponent<UserPlayer>();
    89.         }
    90.  
    91.     }
    92.     [RPC]
    93.     public void RemovePlayer(NetworkPlayer id)
    94.     {
    95.         Player temp = new Player ();
    96.         foreach (Player pl in PlayerList) {
    97.             if(pl.OnlinePlayer == id)
    98.             {
    99.                 temp = pl;
    100.             }
    101.         }
    102.         if (temp != null)
    103.         {
    104.             PlayerList.Remove(temp);
    105.    
    106.         }
    107.  
    108.     }
    109.  
    110.     [RPC]
    111.     public void LoadLevel()
    112.     {
    113.         Application.LoadLevel ("Level");
    114.         MatchStarted = true;
    115.     }
    116.  
    117.     /*void OnLevelWasLoaded(int level)
    118.     {
    119.         if (MatchStarted == true)
    120.             ;
    121.             SpawnPoints = LevelManager.Ins.SpawnPoints;
    122.     }
    123.     */
    124.     public static Player GetPlayer (NetworkPlayer id){
    125.         foreach (Player pl in Instance.PlayerList)
    126.         {
    127.             if (pl.OnlinePlayer == id)
    128.                 return pl;
    129.         }
    130.         return null;
    131.     }
    132.     void OnGUI()
    133.     {
    134.         if (MatchStarted == true && !MyPlayer.IsAlive) {
    135.             if(GUI.Button(new Rect(Screen.width - 50,0,50,20), "Spawn"))
    136.             {
    137.                 MyPlayer.Manager.FirstpersonCont.Spawn();
    138.                 int SpawnIndex = Random.Range(0, LevelManager.Ins.SpawnPoints.Length - 1);
    139.                 MyPlayer.Manager.FirstPerson.localPosition = LevelManager.Ins.SpawnPoints[SpawnIndex].transform.position;
    140.                 MyPlayer.Manager.FirstPerson.localRotation = LevelManager.Ins.SpawnPoints[SpawnIndex].transform.rotation;
    141.                 MyPlayer.Manager.GetComponent<NetworkView>().RPC("Spawn", RPCMode.All);
    142.             }
    143.  
    144.         }
    145.     }
    146.  
    147. }
    148.  
    149.  
    150. [System.Serializable]
    151. public class Player{
    152.     public string PlayerName;
    153.     public NetworkPlayer OnlinePlayer;
    154.     public float Health = 100;
    155.     public UserPlayer Manager;
    156.     public bool IsAlive;
    157. }
    158.  
     
  2. Stefan-Weegink

    Stefan-Weegink

    Joined:
    Feb 4, 2015
    Posts:
    40
    Does anyone know how I could change the rpc's maybe?
     
  3. murkertrer

    murkertrer

    Joined:
    Apr 6, 2014
    Posts:
    1
    Hey Stefan, Have you found a solution? I´ having the same problem.
    Regards