- Home /
Question by
santoshdl2002 · Apr 02, 2017 at 09:54 AM ·
unity 5uinetworking
I have one button and the text in button is the change in value of Sync-variable from all the player . If changes in host is made the value of button is changed in all client but changes in client is not respondind.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking;
public class gamecode :NetworkBehaviour {
[SyncVar(hook="Updateval")]
public string a;
public Button b1;
int i=0,j=0;
void Update () {
b1.GetComponentInChildren<Text> ().text = a;
}
public void buttononclick()// this is button on click event
{
if (!isServer) {
string p = "client";/// want to put the button value if client button is clicked (not responding)
Cmdchangename (p);
} else {
a = "server";/// want to put the button value if client button is clicked(it is responding)
}
}
[Command]
public void Cmdchangename( string newname)
{
a = newname;
}
void Updateval (string newVal) {
a = newVal;
}
}
Comment
Your answer
