Search Unity

event system or unity actions with netcode

Discussion in 'Multiplayer' started by firebird721, Mar 14, 2023.

  1. firebird721

    firebird721

    Joined:
    Jun 8, 2022
    Posts:
    101
    i am trying to wrap my head around how to use events int making my game multyplayer

    i tried checking if the events are neing called somewhere - does anyone listens too the tem - i could find any listenter that hears them

    i put the line - EventsManager.OnPlayerIsDead(NetworkManager.LocalClientId);
    in some places but non of them got listend too..

    how can i work with events and multyplayer in a good way?


    public static class EventsManager
    {

    public static event UnityAction<ulong > PlayerIsDead; //its going only to the battle system

    }

    private void player controler()
    {
    if (!IsServer)
    return;

    case "Player":
    {
    EventsManager.OnPlayerIsDead(NetworkManager.LocalClientId);
    EventsManager.PlayerIsDead( clientId);
    }

    }
    [ServerRpc]
    void killPlayerServerRpc()
    {
    EventsManager.OnPlayerIsDead(NetworkManager.LocalClientId);

    killPlayerClientRpc();
    }


    [ClientRpc]
    void killPlayerClientRpc()
    {
    print("fjvhfjk");
    myPlayerUI.UpdateHealth(0);

    this.gameObject.GetComponent<ShotCollisionDamage>().enabled = false;

    EventsManager.OnPlayerIsDead(NetworkManager.LocalClientId);
    }