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);
}

Comments

  • Gage_IAG
    Gage_IAG ✭✭
    edited December 2018
    Options
    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.