Search Unity

Third Party How to execute code for player on all clients? [Mirror]

Discussion in 'Multiplayer' started by Lekret, Mar 2, 2021.

  1. Lekret

    Lekret

    Joined:
    Sep 10, 2020
    Posts:
    358
    I'm new to networking and making local-host multiplayer game. Probably a stupid qustion, but how to do that?
    I have this code, if damage is applied I need to apply it on all clients and update UI on all clients. How to do that?

    Code (CSharp):
    1. public class Health : NetworkBehaviour
    2. {
    3.     public void ApplyDamage(int damage)
    4.     {
    5.         //change health logic
    6.         HealthChanged.Invoke();
    7.     }
    8. }
     
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Please check out the Mirror documentation and the built in examples :)
     
    Joe-Censored and tobiass like this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You wouldn't normally execute that kind of code "on all clients". Normally you'd do it either on the client with authority over the networked GameObject, or on the host. Then if anything changed, like maybe the current health value, you'd then sync that value to all other clients.