Kills and Deaths

Options
Heya all, I have a bit of a problem.

I'm trying to make a first person shooter that keeps track of kills and deaths. I've already got the deaths working fine. I know how to make the kills increase in number, but my problem is triggering that increase.

Basically, how do I tell my player that he killed the other player? Right now my game is set up so that when you press the left mouse button, it shoots out a ray. When it collides with another player, it sends out an RPC to have the other player take damage. When the player is out of health he gains a death and is destroyed. It's easy to assign him a death because the variable is assigned to his own gameObject. The problem is how do I let the player that killed him know he actually killed him?

Thanks! ^^

EDIT:
A quick update to this. I passed the PhotonNetwork.player.ID over in the RPC so the player that dies knows the killer's ID. With that in mind, is there some way I can access the variables of the ID or find the gameobject with that ID?

EDIT 2:
So I actually figured this one out on my own after a few hours of searching and trial and error haha. I'm not sure if it's the best way to do this but it works. Basically I passed gameObject.GetComponent<PhotonView>().viewID in the RPC to deal damage to the other player. Then I used the other player's script to find out what the ID was and used PhotonView.Find (ID).gameObject.transform; to get the gameObject of that ID. Once the player died it ran an RPC back to the gameObject the ID was set to. That player then ran a few lines of code that gave him a kill.

Comments

  • Tobias
    Options
    I think you are on a good way. If it works for you, it should be fine basically.
    You don't have to pass which ViewID you are affecting or who is calling the RPC though. It's sent internally and you can access it, too.

    The RPC method implementation can have a final parameter which you don't have to send. Like so:

    [code2=csharp][RPC]
    public void SomeRpc(PhotonMessageInfo msgInfo)
    {}[/code2]

    Despite the parameter in the method, you can call SomeRpc as:
    [code2=csharp]this.photonView.RPC("SomeRpc");[/code2]

    The photonView you call RPC on is also the one (and only PhotonView) which executes the RPC call.
    The msgInfo.sender tells you who sent the RPC (who killed someone in your case).

    Hope that helps.