Search Unity

RPC not executed by every player?

Discussion in 'Multiplayer' started by Zathos91, Nov 20, 2014.

  1. Zathos91

    Zathos91

    Joined:
    Aug 26, 2014
    Posts:
    45
    Hi guys, i cant realize what is wrong. I'm already using RPC for lots of things but really i dont know why i cant get working this one with every player that is connected to the room . When this is executed it will give results only on the executing client and not also at the others, here is the code :

    Code (CSharp):
    1. //Checking Collisions with Bullets
    2.     void OnCollisionEnter(Collision col){
    3.         if (col.gameObject.tag == "Bullet") {
    4.             Debug.Log ("Took Damage");
    5.             if(photonView.isMine)
    6.                 takeDamage(col.gameObject.name);
    7.         }
    8.     }
    9.  
    10. //Handling damage
    11.     void takeDamage(string shooter){
    12.         health -= damage;
    13.         if (health <= 0) {
    14.             photonView.RPC("SetKillBoxText",PhotonTargets.All,PhotonNetwork.player.name,shooter);
    15.             anim.SetBool("Die",true);
    16.         }
    17.     }
    18.  
    19.     [RPC]
    20.     public void SetKillBoxText(string killed,string killer){
    21.         killText.text = killed + " was killed by " + killer;
    22.     }
    23.  
    so if player A dies by player B Bullets, only player A will get the text " A was killed by B" ...
    the killtext is just a text object put on playerUI

    why O_O?
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Seems alright. Do you by any chance disable or respawn the player after he died or something like that?
     
    Zathos91 likes this.
  3. Zathos91

    Zathos91

    Joined:
    Aug 26, 2014
    Posts:
    45
    Found the bug : i mistakenly misunderstood the RPC functions -> they will work ONLY in the current object....like you said i disabled this script somewhere during the game but now it's solved...

    thanks as always for the help!