Search Unity

I'm a little unsure about the implementation of network messages

Discussion in 'Multiplayer' started by somedevelopergg, Sep 23, 2021.

  1. somedevelopergg

    somedevelopergg

    Joined:
    Oct 29, 2020
    Posts:
    25
    I use Mirror for nework because there are a lot of convenient tools and because I don't want to get too worried about multiplayer. And I have a little question: there are methods in the mirror for calling the server from the client, and calls to the client (clients) from the server. So how can I trigger an event from a client for other clients? can I call a method on the server where clients will be called? or need another way?

    example of my thought.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Mirror;
    5.  
    6. public class MyNetworkManager : NetworkManager
    7. {
    8.     [Command]
    9.     void CallServer()
    10.     {
    11.         CallClients();
    12.         Debug.Log("Got A Call To Server!");
    13.     }
    14.     [ClientRpc]
    15.     void CallClients()
    16.     {
    17.         Debug.Log("Got A Call From Server!");
    18.     }
    19. }
    20.  
    21.  
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Yes, call a Command on the client, which runs on the server, which calls a ClientRPC on all clients.
     
    somedevelopergg likes this.