show sync var on two text ui (unet - networking)

ok im tired :((

i have a 1 v 1 game and a scrip on them have a score var . the score are sync and i want to show it in two ClientText and ServerText UI Text ! each device show it’s score but not other one .

how can i show the sync var of each one of them on two text ui on their own device ?

[sorry for my bad english]

Hi,
First, SyncVar there are been changed via Command, and you need tell all clients your change via Rpc.
You have some options, and you dont need SyncVars.

public class Example : NetworkBehaviour
{
    // Example without Syncvar

    public int myScore;
    public Text scorePlayer1;
    public Text scorePlayer2;


    // In this case, is  Player1
    public void ScoreUP()
    {
        myScore += 10;
        scorePlayer1.text = myScore.ToString();

        //We call function on server, send it our score
        CmdScoreUp(myScore);

    }
    [Command]
    public void CmdScoreUp(int score)
    {
        // Server say all clients, your score
        RpcScoreUp(score);
    }
    [ClientRpc]
    public void RpcScoreUp(int score)
    {
        // You dont need do this action again, will be do it only your instance on all clients
        if (!isLocalPlayer)
        {
            myScore = score;
            scorePlayer1.text = score.ToString();
        }

    }
}

If you dont understand the mecanism, share your code to adapt.

hey @unidad2pete

how are you doing ? :smiley: :stuck_out_tongue: ME AGAIN :smiley: :))

i am still struggling with rpc and cmd (after few month pause) :expressionless:

ok , do you remember my problem ? i show “myScore” variable on text ui with your codes , now i want send my “point” !

in every playercontroller i have a “point” variable . if player wins it add up with 1 !

i want to every player update “point” variable when a player wins !

sorry for calling you <3 i am confused in unet functions :confused: another guiding from you should solve everything :wink:

Hi,

I have used your code because I have a problem and the texts overlap. My composition is an empty object and within that empty object the canvas with the text, and this composition is added to prebafs in NetworkManager. I don’t know how to fix this.