Hello, this might be a dumb question but I need to clarify
In my multiplayer turn-based game, on turn change cards are drawn face down for everyone but the player in turn
The player in turn can click on cards to mark them as selected, I need to notify other players that that card has been selected
What I did was
{
ToggleCardSelectionServerRpc(cardIndex, true)
}
[Rpc(SendTo.Server)]
void ToggleCardSelectionServerRpc(int index, bool selected)
{
ToggleCardSelectionClientRpc(index, selected);
}
[Rpc(SendTo.ClientsAndHost)]
void ToggleCardSelectionClientRpc(int index, bool selected)
{
var card = cardsToSelectedState.Keys.ElementAtOrDefault(index);
if (card == null)
{
Debug.LogError("Card not found in ToggleCardSelectionRpc");
return;
}
var cardHover = card.GetComponent<CardHover>();
cardHover.ToggleSelection(selected);
}
so it sends to server, then server sends to all clients.
Is this common? As I've done it a lot of time and it feels more like boilerplate at this point.
or is this the usual way to do things?
I've thought about using NetworkVariables but they wouldn't be enough for everything my game needs.
Also is it wrong to just call ToggleCardSelectionClientRpc from client (non-host) side. From my understanding that would break the server-client authoritative model.
If you need more information or my words unclear please let me know.
Thanks in advance