Question by
kekland · Mar 03, 2016 at 02:30 PM ·
networkingunity 5.2
ClientRpc doesnt call on local client
I want to make chat, but this script doesn't work. (Im new at networking, so sry if im noob :D) using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI;
public class ChatManager : NetworkBehaviour {
string lastMessage;
public Text chat;
public Text t;
public Button sButton;
void Start()
{
if (isLocalPlayer)
{
t = GameObject.Find("InputFieldText").GetComponent<Text>();
sButton = GameObject.Find("SendButton").GetComponent<Button>();
sButton.onClick.AddListener(() => SendMessage());
chat = GameObject.Find("ChatText").GetComponent<Text>();
}
}
public void SendMessage()
{
lastMessage = t.text;
Debug.Log("Sended message : " + lastMessage);
t.text = string.Empty;
CmdSendMessage(lastMessage);
}
[Command]
void CmdSendMessage(string msg)
{
RpcRecieveMessage("Test : " + msg);
}
[ClientRpc]
void RpcRecieveMessage(string msg)
{
if (isLocalPlayer)
{
Debug.Log("Got message : " + msg);
chat.text = chat.text + "\n" + msg;
}
}
}
So, when host sends message to client, nothing happens. Same on client-host side. I think that's because of RPC not calling on local player. Idk how to fix it, help me pls :)
Comment
Your answer
Follow this Question
Related Questions
[UNET 5.2] Multiple local authority for 1 object? 0 Answers
NetworkServer.Spawn() make client crash to desktop when called in a loop 1 Answer
Best way to interact with remote players on the client? 1 Answer
(C#) UDP broadcast between unity editor and windows phone 0 Answers
Networking 3rd party server 0 Answers