Send Text Over Network
Hi, I am trying to get a string sent over the network so that when a player hits a button ('g') the Text object will be updated with new text. What I have so far is as follows:
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using System.Collections;
public class NTC : NetworkBehaviour {
[SyncVar]
private string broadcastMessage = "textwillgohere";
public Text theText;
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown (KeyCode.G))
{
TransmitText ("It worked!");
}
theText.text = broadcastMessage;
}
[Command]
void CmdProvideTextToServer(string inputText)
{
broadcastMessage = inputText;
}
[ClientCallback]
void TransmitText(string inputText)
{
CmdProvideTextToServer (inputText);
}
}
This code is attached to an empty GameObject with a NetworkIdentity and it changes a Text object in the scene that has no NetworkIdentity (I don't think this matters). So as is, it works if I press 'g' on the client who is also the host but not if I press 'g' on any other client (called a remote client?) How can I get it so that if anyone presses 'g' the text will change? Thanks!
Your answer
Follow this Question
Related Questions
Network Soccer Ball Position jitter, sending transform position late? 0 Answers
UNET AssetID 0000 zero 0 Answers
PLS recommend plugins for networking/sever which ONLY work for authentication + storing player info. 0 Answers
Couldn't delete cache in UnityWebRequest 0 Answers
Lerping to Smooth Network Movement 0 Answers