Why cannot I destroy the player?

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

Best Answer

Answers

  • RominRomin
    edited June 8
    [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 issue
  • TomzaTomza
    edited June 8
    Romin 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 issue

    But if I try to write without the if(photonview.isMine) line, the player who is shooting is killed. In other words, it commits suicide.

Sign In or Register to comment.