How to network canvas elements ??

Helllo,

I am developing networking quiz game which 2 players are getting one question with 4 answers.

I want to network the question and its answers in the client but i can’t do that. i handled answers like enemies or non-player objects in unity tutorial but no point

How can i do that ??
Also i can’t network the text of the question ??

So i want to ask should i handle canvas ui elements with another method or what ?

Thanks in advance :slight_smile:

I might be mistaken but when you create the player prefab you put the canvas inside as a child.
After creating the Canvas object you uncheck his Canvas component(The canvas should disapear from the scene)
Then you create a script and put them as a component of your player object prefab.
The script should containn the following:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class OnlyLocalCanvas : NetworkBehaviour {
// Use this for initialization
    void Start()
    {
           if (isLocalPlayer)
           {
                 GetComponentInChildren<Canvas>().enabled = true;
           }
    }
}


Note that the script has a using UnityEngine.Networking; and tthe class is NetworkBehaviour insted of MonoBehaviour.

You should be good to go!

What this does is when a player spawns in the Network that player (And only that player) can see the Canvas!
By default the others players canvas are disabled! it only enables yours [ if(isLocalPlayer) ]

Hi,

I think the best idea will be to have a server and an API. The server will be the game manager, and will send questions/answers to remote clients (with json, xml, or whatever you want). Everything will be synchronize and manage by the server.