- Home /
Info on Photon PUN RPC calls.
Hi, I have a question about RPC and Photon PUN.
I have 1 GameObject in my game that calls an RPC method. This game object contains a C# script (that contains the RPC method) and the PhotonView component with/without (is should be the same) the observed script and the ObserveOption equals to Off.
I have a character which have to shoot to a cube. This cube has the previously described script and component attach to it.
The RPC is sent once (when the cube has been collided with a projectile) but in my scene I have many Cube which should receive the message because I have to decrease the health of the hit cube. The problem is that only 1 Cube receive the RPC call (The RPC is caught by the first instantiated object at the start of the game) but the RPC should be received by all the cube (is that right?) in my scene.
The cubes are exactly the same but they have a different photonView ID (rightly) so we could check whether the hit cube to which decrease the health is the right one.
This is the significant part of the code:
public static void reduceHealthRPC(float damage, int viewID)
{
photonView.RPC("reduceHealth", PhotonTargets.All, damage, viewID);
}
[RPC]
public void reduceHealth(float damage, int viewID)
{
if(this._viewID != viewID)
{
Debug.Log ("The view ID is not mine. My viewID is: " + _viewID + ", and the one which is coming form RPC is: " + viewID);
return;
}
currentHealth -= damage;
Debug.Log("My life is: " + currentHealth);
}
Please help me to unerstand what I'm doing wrong. Thank you.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers