How do I make a spawned missile tell the hit player who shot it? (photon)

Hi,

In my multiplayer game when a player shoots a missile I photon instantiate it:

GameObject GO = PhotonNetwork.Instantiate(MissilePrefab.name, muzzle2.position, transform.rotation, 0);
        GO.GetComponent<Missile>().myAttacker = gameObject.name;

The second line tells the missile script that the public string “myAttacker” which is in the missile script is named after the sender of the missile.

When the missile hits a player I then want that player to detect that string, or who shot the missile.

So on the missile script - OnCollisionEnter I have this:

 if (coll.gameObject.tag == "John")
            {         
                GetComponent<PhotonView>().RPC("NameOfAttacker", PhotonTargets.All, myAttackerF);
           }

And the RPC NameOfAttacker looks like this:

  [PunRPC]
    void NameOfAttacker(Collision coll/*, string attacker*/)
    {
       
        DidIDie d = coll.gameObject.GetComponent<DidIDie>();
        d.myAttackerD = myAttacker;

    }

“DidIDie” script is on the player tagged “John” and has another public string named "myAttackerD " and I was hoping that myAttackerD would be equal to myAttacker but instead I get this error:
PhotonView with ID 1015 has no method “NameOfAttacker” that takes 1 argument(s): String

I’m stuck, does anyone know what I’m doing wrong and how to have the string “myAttackerD” on “john”'s script be the name of the person who fired the missile?

  • Wouldn’t it be better to use player ID instead of a name string? Photon Unity Networking 2: Player Class Reference
  • The error message is pretty descriptive. It’s looking for a method with a single string argument, since that’s what you’re passing as the end of the RPC call. You have a single Collision argument instead. I’m not sure Photon can directly Serialize an entire collision object either.
1 Like

ah wonderful. Thank you for explaining and the link, I’ll investigate further