Search Unity

Call RPC without having a attached to gameObject

Discussion in 'Multiplayer' started by siOnzeeSlav, Apr 8, 2014.

  1. siOnzeeSlav

    siOnzeeSlav

    Joined:
    Jun 8, 2013
    Posts:
    7
    Hi, Sorry if this question already exist, but I don't found question with this.

    I have Server.cs and Client.cs

    That mean

    On loading check if computer is Client or Server, then assign on gameObject script.
    So my problem is here now.

    Client onConnect call
    Code (csharp):
    1. networkView.RPC("check_my_id", RPCMode.Server, _id);


    The host in server.cs (what is assigned to gameObject) have:
    Code (csharp):
    1. [RPC]
    2. void check_my_id(int id, NetworkMessageInfo info) {
    3.  
    4. }
    Problem is that, RPC cannot be execused, because the connected player don't have assigned to gameObject Server.cs

    Is there way how to do it?
    I don't want have assigned from Client side (Server.cs script)...

    Error:
    RPC call failed because the function 'testRPC' does not exist in the any script attached to'Camera'



    Yeah! I Got it! :)


    Soo, here is my solution:: between diferent class.

    Server.cs

    Code (csharp):
    1. [RPC]
    2.     void testRPC(){
    3.         Debug.Log("TESTRPC"); //So this was written on server :))
    4.     }
    Client.cs
    Code (csharp):
    1.  
    2.  
    3. void Start() {
    4.    networkView.RPC("testRPC", RPCMode.Server);
    5. }
    6.  
    7.  [RPC]
    8.     void testRPC() { //Now method rpc exist, can post error and send to server.
    9.        
    10.     }
     
    Last edited: Apr 8, 2014