-1

How to execute RPC calls on all clients when this method sent from one client? Is it exists some solution in Unity netcode like RPCTargets.All in Photon?

1 Answers1

0

There you go

using UnityEngine;
using Mirror;

public class ExampleChangeSomething : NetworkBehaviour // ->Inherit from NetworkBehaviour
{
    void Start()
    {
        UI_ChangeSomething();
    }


    //Attach this to the Button click or call this function from somewhere(e.g. I call this on Start)
    public void UI_ChangeSomething()
    {
        //Client Send command to the Server
        Cmd_ChangeSomething("Please Print this Text");
    }

    //Execute this on Server
    [Command]
    void Cmd_ChangeSomething(string _text)
    {
        //The server then tell every Clients to execute the "Rpc_ChangeSomething" Function
        Rpc_ChangeSomething(_text);
    }



    [ClientRpc]
    void Rpc_ChangeSomething(string _text)
    {
        ChangeSomething(_text);
    }


    //the logic that needs to be executed by Every Client
    private void ChangeSomething(string _text)
    {
        //your logic here.
        Debug.Log(_text); // every client will print "Please Print this Text" in their Console

    }
}
Hikari
  • 458
  • 1
  • 11
  • 27