Access to a specific player's variable
Options
Hi friends, I am developing a game using photonnetwork,
I want to do this, I want to write a text ("Target accepted") to a specific player's text variable using RPC.
I've written a code as follows, but it doesn't write anything in the text variable.Interestingly The unity editor debug console also writes "Target accepted".
Do you think what is wrong, or is there a method you can suggest?
public void OwnerKabul()
{
view.RPC("TargetAcceptRpc", PhotonTargets.AllViaServer, sender.gameObject.GetPhotonView().viewID, target.gameObject.GetPhotonView().viewID);
}
[PunRPC]
void TargetAcceptRpc(int senderView, int targetView)
{
sender = PhotonView.Find(senderView).transform;
target = PhotonView.Find(targetView).transform;
sender.GetComponent().isOwner = true;
target.GetComponent().isOwner = true;
if(view.isMine)
{
targetUserName.text = target.GetComponent().owner.NickName;
}
else
{
targetUserName.text = sender.GetComponent().owner.NickName;
}
target.GetComponent().targetAcceptText.text = "Target accepted";
Debug.Log("Look here " + target.GetComponent().targetAcceptText.text);
//canvas.gameObject.SetActive(false);
}
I want to do this, I want to write a text ("Target accepted") to a specific player's text variable using RPC.
I've written a code as follows, but it doesn't write anything in the text variable.Interestingly The unity editor debug console also writes "Target accepted".
Do you think what is wrong, or is there a method you can suggest?
public void OwnerKabul()
{
view.RPC("TargetAcceptRpc", PhotonTargets.AllViaServer, sender.gameObject.GetPhotonView().viewID, target.gameObject.GetPhotonView().viewID);
}
[PunRPC]
void TargetAcceptRpc(int senderView, int targetView)
{
sender = PhotonView.Find(senderView).transform;
target = PhotonView.Find(targetView).transform;
sender.GetComponent().isOwner = true;
target.GetComponent().isOwner = true;
if(view.isMine)
{
targetUserName.text = target.GetComponent().owner.NickName;
}
else
{
targetUserName.text = sender.GetComponent().owner.NickName;
}
target.GetComponent().targetAcceptText.text = "Target accepted";
Debug.Log("Look here " + target.GetComponent().targetAcceptText.text);
//canvas.gameObject.SetActive(false);
}
0
Comments
-
You can actually do this pretty simply by calling the RPC on the object that has the RPC script, as such:
Me:void ShootGun(int damage) { raycastTarget.GetComponent<PhotonView>().RPC("ReceiveDamage", PhotonTargets.AllBuffered, damage); }
Target:[PunRPC] public void ReceiveDamage(int damage) { this.currentHealth -= damage; CheckHealth(); }
void CheckHealth() { if (this.photonView.isMine && this.currentHealth <= 0) { PhotonNetwork.Destroy(this.gameObject); } }
-
This is of course an example, but you get the idea enough to retrofit it to your application.
I may have misread your issue, but hopefully this helps. If not let me know and we can debug it.0