1. using UnityEngine;using System.Collections;
  2.  
  3.  
  4. public class NetworkExample : MonoBehaviour {
  5.    
  6. /*
  7.  
  8.  
  9. ------------------------------------------------------------
  10. This was the only two debug prints on client side:
  11.  
  12.  
  13.  
  14.  
  15. CLIENT:NetworkExample:OnConnectedToServer()
  16.  
  17.     (this server responded in its log here)
  18.  
  19.  
  20. CLIENT:NetworkExample:RPC:Client_PlayerExampleResponse(Client,1)
  21.  
  22.  
  23.  
  24. ------------------------------------------------------------
  25. This was the only debug print on server side:
  26.  
  27.  
  28. SERVER:NetworkExample:RPC:Server_PlayerExampleRequest(Client,1)
  29.  
  30. */   
  31.    
  32.  
  33.  
  34.    
  35. //--------------------------------------------------------------------------------------------------   
  36. // VARIABLES
  37. //--------------------------------------------------------------------------------------------------   
  38.     public bool debugactive = true;
  39.     public string PlayerName;
  40.    
  41.    
  42.    
  43. //----------- This is an example of having the Client send a request to the Server:
  44.     void OnConnectedToServer()
  45.     {
  46.         PlayerName = PlayerPrefs.GetString("PlayerName");
  47.         if(debugactive){ if(Network.isServer){Debug.Log ("SERVER:NetworkExample:OnConnectedToServer()");}else{Debug.Log ("CLIENT:NetworkExample:OnConnectedToServer()");}}
  48.         networkView.RPC("Server_PlayerExampleRequest",RPCMode.Server,PlayerName,Network.player);
  49.     }
  50.    
  51. //----------- This is an example of the Server receiving a request from the client and calling the client back.
  52.     [RPC]
  53.     void Server_PlayerExampleRequest(string playername, NetworkPlayer view)
  54.     {
  55.         if(debugactive){ if(Network.isServer){Debug.Log("SERVER:NetworkExample:RPC:Server_PlayerExampleRequest("+playername+","+view+")");}else{Debug.Log("CLIENT:NetworkExample:RPC:Server_PlayerExampleRequest("+playername+","+view+")");}}
  56.         //networkView.RPC("Client_PlayerExampleResponse",RPCMode.All, playername, view);   
  57.         networkView.RPC("Client_PlayerExampleResponse",view, playername, view)// responding only to the player 'view' that sent the RPC
  58.     }
  59. //----------- This is an example of the Client receiving a call back from the server.
  60.     [RPC]
  61.     void Client_PlayerExampleResponse(string playername, NetworkPlayer view)
  62.     {
  63.         if(debugactive){ if(Network.isServer){Debug.Log("SERVER:NetworkExample:RPC:Client_PlayerExampleResponse("+playername+","+view+")");}else{Debug.Log("CLIENT:NetworkExample:RPC:Client_PlayerExampleResponse("+playername+","+view+")");}}
  64.     }
  65.    
  66.    
  67.    
  68.    
  69.    
  70.     // Use this for initialization
  71.     void Start () {
  72.    
  73.     }
  74.    
  75.     // Update is called once per frame
  76.     void Update () {
  77.    
  78.     }
  79. }