When I have two players and I shoot another player with my gun they lose health, but when they die I die and they stay alive, both players get a kill. Here is the code:
[PunRPC]
public void DestroySpaceship(int killer)
{
Health = 5;
rb.velocity = Vector3.zero;
rb.angularVelocity = Vector3.zero;
//rb.enabled = false;
controllable = false;
if(killer == photonView.ViewID)
{
Debug.Log("I killed :)");
}
if (photonView.IsMine)
{
object lives;
if (PhotonNetwork.LocalPlayer.CustomProperties.TryGetValue(AsteroidsGame.PLAYER_LIVES, out lives))
{
PhotonNetwork.LocalPlayer.SetCustomProperties(new Hashtable {{AsteroidsGame.PLAYER_LIVES, ((int) lives <= 1) ? 0 : ((int) lives - 1)}});
StartCoroutine("WaitForRespawn");
if (((int) lives) > 1)
{
StartCoroutine("WaitForRespawn");
}
}
}
}
[PunRPC]
public void Fire(Vector3 posit,Vector3 rotat, int hitter, PhotonMessageInfo info)
{
float lag = (float) (PhotonNetwork.Time - info.SentServerTime);
RaycastHit hit;
/** Use this if you want to fire one bullet at a time **/
Physics.Raycast(posit, rotat, out hit);
if(hit.collider)
{
//" && hitter != photonView.ViewID
if(hit.collider.tag == "me")
{
Health--;
Debug.Log(Health);
if(Health <= 0)
{
photonView.RPC("DestroySpaceship", RpcTarget.AllViaServer, hitter);
}
}
else if(hit.collider.tag == "Player")
{
Instantiate(blood,hit.point,Quaternion.Euler(-rotat));
}
else{
Instantiate(impact,hit.point,Quaternion.Euler(-rotat));
}
}
}
There are a couple other bugs that occur after you have killed where you can’t get damaged or something but I haven’t found out what is happening yet so I will see if that is there after this is fixed.