nate300and4
nate300and4

Reputation: 11

How do you reference the Player Class in Photon Unity Networking 2?

I'm trying to send an Rpc to a specific Player, but I can't use the get function from the Player class, I have to setup a player variable first, but I can't have the player variable equal anything except null if I can't reference the player. I have been wholly unable to come across any information after scouring the internet for an hour.

I've tried using references to photonView and tried to reference Player through GetComponent(); which always ended in the error "ArgumentException: GetComponent requires that the requested component 'Player' derives from MonoBehaviour or Component or is an interface"

Before the Photon change to Photon 2 it worked fine and my code was:

other.photonView.RPC("Reflect", PhotonPlayer.Find(other.GetComponent<PhotonView>().ownerId))

And after trying for a couple hours to fix it I have this:

other.photonView.RPC("Reflect", GameObject.Find("Game Manager").GetComponent<Player>().Get(other.GetComponent<PhotonView>().OwnerActorNr));

I expected to be able to find a player by id/actor number without needing a player referenced already, but it appears that I need to have that reference. It doesn't make any sense to me as to why or what I've done wrong.

Upvotes: 0

Views: 1482

Answers (1)

JohnTube
JohnTube

Reputation: 1812

It should be simple as the PhotonView class has Owner and OwnerActorNr;

photonView.RPC("RpcMethodName", photonView.Owner));

Upvotes: 2

Related Questions