简体   繁体   English

你如何在Photon Unity Networking 2中引用Player类?

[英]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. 我正在尝试将Rpc发送到特定的播放器,但是我不能使用Player类中的get函数,我必须首先设置一个播放器变量,但我不能让播放器变量等于除null之外的任何内容我无法引用播放器。 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(); 我尝试使用对photonView的引用,并尝试通过GetComponent()引用Player; which always ended in the error "ArgumentException: GetComponent requires that the requested component 'Player' derives from MonoBehaviour or Component or is an interface" 总是以错误结尾“ArgumentException:GetComponent要求所请求的组件'Player'来自MonoBehaviour或Component,或者是一个接口”

Before the Photon change to Photon 2 it worked fine and my code was: 在Photon改为Photon 2之前,它工作正常,我的代码是:

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. 我希望能够通过id / actor编号找到一个玩家而不需要已经引用的玩家,但看起来我需要有这个参考。 It doesn't make any sense to me as to why or what I've done wrong. 对我来说,为什么或我做错了什么都没有任何意义。

它应该很简单,因为PhotonView类有OwnerOwnerActorNr ;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM