Hi everyone, I've got an big issues, and I spend days to find an answer but nothing works.. So at the beginning of my game, I've got an small mini-game where everyone roll a dice to decide which player is the first. And I found no way to synchronise the number with every client! I tried, RPC, Sync Hook, everything I found on the internet.. Here is my current not working script.. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking; public class RandomDice : NetworkBehaviour { public Text Number; //[SyncVar(hook = "TextOnServer")] public string RndmNumber; public void RandomNumber(){ TextOnServer(Random.Range(1, 7).ToString()); } private void Update() { Number.text = RndmNumber; } void TextOnServer(string DiceNumber){ Debug.Log(DiceNumber); RndmNumber = DiceNumber; Number.text = RndmNumber; } } It would be very kind of you to explain to me, show me exemples, to make it work.. thank you very much.
Untested, unsupported, un-everything, but might help put you on the right track. Code (CSharp): public class RandomDice : UnityEngine.Networking.NetworkBehaviour { int rollsRequiredBeforeStarting = 4; Dictionary<int, int> diceRolls = new Dictionary<int, int>(); int playerId = -1; bool pickedFirstPlayer = false; public override void OnStartClient() { //playerId = GetMyPlayerId(); CmdMyDiceRoll(Random.Range(0, 6), playerId); } void Update() { if(isServer && !pickedFirstPlayer) { if(diceRolls.Count >= rollsRequiredBeforeStarting) { var firstPlayer = -1; var highestRoll = -1; foreach(var item in diceRolls) { if(item.Value > highestRoll) { highestRoll = item.Value; firstPlayer = item.Key; } } RpcPlayerToGoFirst(firstPlayer); pickedFirstPlayer = true; } } } [Command] void CmdMyDiceRoll(int roll, int playerId) { diceRolls[playerId] = roll; } [ClientRpc] void RpcPlayerToGoFirst(int playerId) { if(playerId == this.playerId) { // wee i get to go first! } } }