Search code examples
c#unity-game-enginerpcphoton

Why Calling An RPC Function With An Integer Parameter Gives Error? -Photon Unity


I am Using Photon 2 And I Have Public Rpc Function In One Of My Script, The Function Has An Integer Parameter, This Is How My Function Exactly Looks Like.

    [PunRPC]
    public void TakeDamage(int amount)
    { 
        playerHealth -= amount;
        if (playerHealth <= 0)
        {
            Debug.Log("Player Died");        
        }
    }

We In Above Code The TakeDamage Function Takes An Integer Called amount. So When I am Calling This Function From Other Scripts, And When The Other scripts Actually Call The Function It Gives A Warning.

How I am Calling The Fucntion

PV.RPC("currentTarget.TakeDamage",  RpcTarget.AllBuffered, damage);

The PV is a public PhotonView.


The Warning

RPC method 'currentTarget.TakeDamage(Int32)' not found on object with PhotonView 1003. Implement as non-static. Apply [PunRPC]. Components on children are not found.

Solution

  • you have to give function name ("TakeDamage") instead of "currentTarget.TakeDamage" in RPC function.