Okay. This is whats happening, I have a user that hosts a server, and other users connect as clients. Its a chat system I'm trying to make, so if a Client writes, he can see his own message, but he can't see any other messages written by anyone else. The Server, he can write messages also, he can see his own messages and other client's messages also. So the problem is I'm not sure what i'm doing wrong as why the clients can't see other messages but their own, and the server can see all messages. The scenary i have a ez gui ScrolList, that i have a network component to it, and the script is on it as well:
The network view is placed on the ScrollList and also this script, and also i have network view's on each ScrollItem, but i remove and add them doesn't matter wether they're there or not, its the same effect, plus the items go in the scrolllist anyways. also the Debug.Log does work When its doing the RPC, and everywhere else. So basically the way i see it now is that it Create's item only to the server and the person that is writing it (for clients) and for the server it creates items from himself and everyone else (by creating item that's the message that appears, so the server can see everyeone's msgs, but clients only their own.)
I'm using ez gui for input filed's etc. and the list item in the scroll list.
using UnityEngine; using System.Collections;
public class ChatWRITE : MonoBehaviour { public GameObject Message; public UITextField InputMSG; public UITextField name; public UIScrollList ChatLIST; public SpriteText NEWMSG; public static ChatWRITE CH; public GameObject MSGPREFAB; private bool canI; // Update is called once per frame void Awake() { CH = this; }
void Update()
{
if (Input.GetKey(KeyCode.Return) && InputMSG.Text != "")
{
if (Network.isServer)
ApplyGlobalChatText(NEWMSG.Text);
NEWMSG.Text = Color.red + name.Text + Color.white + ": " + InputMSG.Text;
// networkView.RPC("ApplyGlobalChatText", RPCMode.Others, NEWMSG.Text);
networkView.RPC("ApplyGlobalChatText", RPCMode.All, NEWMSG.Text);
// UIListItem tmpMSG = (UIListItem)ChatLIST.CreateItem(Message, NEWMSG.Text);
InputMSG.Text = "";
InputMSG.Clear();
InputMSG.SetColor(Color.red);
ChatLIST.ScrollPosition = 1;
canI = true;
}
if (canI)
{
// InputMSG.controlIsEnabled = true;
UIManager.instance.FocusObject = InputMSG;
}
} // Update finishes
[RPC]
public void ApplyGlobalChatText(string MSG)
{
UIListItem tmpMSG = (UIListItem)ChatLIST.CreateItem(Message, MSG);
Debug.Log("SUPPOSED TO ADD AN EXTRA ITEM NOW");
}
void OnConnectedToServer()
{
NEWMSG.Text = Color.red + name.Text + Color.white + " HAS JOINED TEH CHAT";
networkView.RPC("ApplyGlobalChatText", RPCMode.All, NEWMSG.Text);
Debug.Log("CONNECTED TO SERVER AND ADDING A MSG");
}
void OnPlayerDisconnected(NetworkPlayer player)
{
NEWMSG.Text = Color.red + name.Text + Color.green + " HAS LEFT THE CHAT";
networkView.RPC("ApplyGlobalChatText", RPCMode.All, NEWMSG.Text);
Debug.Log("DSICONNECTED FROM SERVER AND ADDING A MESSAGE");
}
}