Why cannot I destroy the player?
Tomza
✭
The code:
public void SetHit(float damage){ photonView.RPC("SetHitRPC",PhotonTargets.All,damage); } [PunRPC] void SetHitRPC(float damage,PhotonMessageInfo info){ if(this.photonView.isMine){ Debug.Log("SetHit"); if(health > 0){ health -= damage; mk_UIController.healthText.text = health.ToString(); } if(health <= 0){ health = 0; if(onDeath != null){ onDeath("Test");//info.sender.NickName } if(onRespawn != null){ onRespawn(5.0f); } Debug.Log("SetHitRPC"); StartCoroutine(DestroyPlayerCor()); } } } IEnumerator DestroyPlayerCor(){ yield return new WaitForSeconds(2.0f); Debug.Log("death"); PhotonNetwork.Destroy(gameObject); }
0
Best Answer
-
Hi @Tomza,
if you want to update the health value on each client, you have to remove theisMine
condition, otherwise only the owner of the object will update the health value and furthermore the UI (as far as I can see). If the player object dies and you have to remove it by usingPhotonNetwork.Destroy(...)
, you have to add theisMine
condition before that call, because only the owner of an object can remove it (unless you are the MasterClient and use another function call).5
Answers
-
[PunRPC] void SetHitRPC(float damage,PhotonMessageInfo info){ if(this.photonView.isMine){ Debug.Log("SetHit")
;
Your RPC should not checkif(photonview.isMine)
that is the issue0 -
But if I try to write without theRomin said:[PunRPC]
void SetHitRPC(float damage,PhotonMessageInfo info){
if(this.photonView.isMine){
Debug.Log("SetHit");
Your RPC should not check if(photonview.isMine) that is the issueif(photonview.isMine)
line, the player who is shooting is killed. In other words, it commits suicide.
0 -
Hi @Tomza,
if you want to update the health value on each client, you have to remove theisMine
condition, otherwise only the owner of the object will update the health value and furthermore the UI (as far as I can see). If the player object dies and you have to remove it by usingPhotonNetwork.Destroy(...)
, you have to add theisMine
condition before that call, because only the owner of an object can remove it (unless you are the MasterClient and use another function call).5