- Home /
Question by
thecoolracer · Aug 15, 2014 at 10:18 AM ·
networkingphotonrpcchat
The other client does not receive chat messages.(Photon Networking)
The client that sent the message receives it and other players in the room do not receive the RPC. Weird.
using UnityEngine;
using System.Collections;
public class ChatManager : Photon.MonoBehaviour {
public bool enteringMessage;
public string sentMessage;
public string nickName;
public string msg1;
public string msg2;
public string msg3;
public string msg4;
public string msg5;
public string msg6;
// Use this for initialization
void Start () {
if(photonView.isMine) {
nickName = NickName.nick;
msg1 = "";
msg2 = "";
msg3 = "";
msg4 = "";
msg5 = "";
msg6 = "";
}
}
void Update() {
if(photonView.isMine) {
if(Input.GetKeyDown (KeyCode.T)) {
if(!enteringMessage) {
enteringMessage = true;
//GUI.FocusControl ("ChatBox");
}
}
if(Input.GetKeyDown (KeyCode.Return)) {
if(enteringMessage) {
photonView.RPC ("SendChat", PhotonTargets.All, (nickName + " - " + sentMessage));
enteringMessage = false;
sentMessage = "";
Screen.lockCursor = true;
}
}
}
}
void OnGUI () {
if(photonView.isMine) {
GUI.Box (new Rect(0, Screen.height - 230, 580, 180), "Press T to chat");
GUI.Label (new Rect(10,Screen.height - 200, 500, 20), msg6);
GUI.Label (new Rect(10,Screen.height - 180, 500, 20), msg5);
GUI.Label (new Rect(10,Screen.height - 160, 500, 20), msg4);
GUI.Label (new Rect(10,Screen.height - 140, 500, 20), msg3);
GUI.Label (new Rect(10,Screen.height - 120, 500, 20), msg2);
GUI.Label (new Rect(10,Screen.height - 100, 500, 20), msg1);
if(enteringMessage) {
Screen.lockCursor = false;
GUI.SetNextControlName ("ChatBox");
sentMessage = GUI.TextField (new Rect(10,Screen.height - 80, 500, 20), sentMessage, 255);
if(GUI.Button (new Rect(520,Screen.height - 80, 50, 20), "SEND")) {
photonView.RPC ("SendChat", PhotonTargets.All, (nickName + " : " + sentMessage));
enteringMessage = false;
sentMessage = "";
Screen.lockCursor = true;
}
}
}
}
[RPC]
void SendChat (string message) {
msg6 = msg5;
msg5 = msg4;
msg4 = msg3;
msg3 = msg2;
msg2 = msg1;
msg1 = message;
}
}
Comment
Best Answer
Answer by thecoolracer · Aug 15, 2014 at 12:33 PM
Fixed it. I made it loop every ChatManager in room, because it was only calling the RPC on mine.