Hello, I have a problem that only one client seems to affect a value in script. Here is the enemy script
float health;
public void Update()
{
DisplayHealth();
}
public void DisplayHealth()
{
healthText.text = health.ToString();
}
public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
stream.SendNext(health);
}
else
{
this.health = (float)stream.ReceiveNext();
}
}
And here is the bullet script (bullet is instantiated by player and specific player is owner - I’ve read that only one player should check for collisions - that’s why there is this if(photonView.IsMine))
private void OnCollisionEnter2D(Collision2D collision)
{
if (!photonView.IsMine) return;
if (collision.gameObject.tag == "Enemy")
{
collision.gameObject.GetComponent<EnemyController>().health -= 10;
}
}
When one player shoots enemy health updates on all clients. When another player shoots enemy then health changes and goes back to previous value.