- Home /
whoHit me most? Photon
I'm trying to find out who hit xPlayer Most times:
and i've replaced the initial question with the following:
a bit of sleep and pseudo code later: I think this should do it... @ Work, so I can't test.
void OnCollisionEnter(Collision collision){
if(collision.gameObject.tag == "weapon")
{
pv = collision.collider.GetComponent<PhotonView>();
swordID = pv.viewID-3;
ownerID = photonView.viewID;
//---------------------------
ownLog[swordID]+=1;//meaning I've been hit by swordIDxTimes
if(swordID>newestID)
newestID = swordID;
//---------------------------
Debug.Log ("colliderID:"+swordID+" owner's: "+ownerID);
this.myPhotonView.RPC("success", PhotonTargets.AllBuffered);
}
}
below checks if player is dead, runs through players who've hit this player asking how many times they hit this player, clearing the other player's hit count on this player(since this player is dead already), grabbing the highest score into winnerID; and lastly checking who has killed the player
[RPC]
private void success(){
if(hpWidth>0.0f){
hpWidth-=0.5f;
}
else{
//--------------------
for(int check = 1; check<newestID; check+=1000)
{if(ownLog[check]>ownLog[winnerID])
winnerID=check;
ownLog[check]=0;
}
//--------------------
hpWidth=0.0f;
swordW.particleSystem.renderer.enabled = false;
player.renderer.enabled = false;
swordS.renderer.enabled = false;
swordW.renderer.enabled = false;
sheildW.renderer.enabled = false;
sheilds.renderer.enabled = false;
}
if(myPhotonView.PhotonView.viewID == winnerID && hpWidth==0.0f;)
kills+=1;
this.myPhotonView.RPC("updateHP", PhotonTargets.AllBuffered, hpWidth);
}
I feel like the below statement is already incorrect...
if(myPhotonView.PhotonView.viewID == winnerID && hpWidth==0.0f;)
kills+=1;
if(myPhotonView.PhotonView.viewID == winnerID)
{ kills+=1;
winnerID=0;
}
Hmm... That's why it looked funny... need to broadcast just to the winner, that they've killed someone.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130910im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Photon]Player dies when new player connects 0 Answers
Collision Damage, Hit points and Instantiate 1 Answer
Robot Not Taking Damage 0 Answers
Health Regeneration 2 Answers
Floating damage text? 2 Answers