- Home /
how to add private chat in multuplayer game.
Hi everybody, i have created multiplayer game using photon network service. here i want to add private chat by click on remote player chat window should be open for both players. I have tried following script/tricks but its work for only public chat not particular player bcoz of photonTargets.
this.photonView.RPC ("Chat", PhotonTargets.All, this.inputLine);
here only photonTargets.All, OthersBuffered, AllBuffered & MasterClient is there. thats why message going to public. but i wnat it will be something like(photonTargets.clickedPlayer) here clickedPlayer is the player there only messase shold go.
Thanks
Answer by Dreamora · Aug 18, 2014 at 02:52 PM
To send a message only to a specific player, you would provide the photon player there instead of PhotonTargets The PhotonTargets enumeration is meant for cases where you want to target whole parts of the room.
Answer by JITENDRA-RAJ · Sep 04, 2014 at 07:01 AM
Like finding id of players we can send messages to particular player. Thanks for Dreamora Concepts
if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Return)) {
if (!string.IsNullOrEmpty (this.inputLine)) {
if(photonView.owner == PhotonPlayer.Find (RecieverId)){
this.photonView.RPC ("Chat", PhotonPlayer.Find (RecieverId), this.inputLine);
}else{
this.photonView.RPC ("Chat", PhotonPlayer.Find (SenderId), this.inputLine);
}
messages.Add (PhotonNetwork.playerName + ": " + inputLine);
this.inputLine = "";
GUI.FocusControl ("");
return; // printing the now modified list would result in an error. to avoid this, we just skip this single frame
} else {
GUI.FocusControl ("ChatInput");
}
}
[RPC]
public void Chat(string newLine, PhotonMessageInfo mi)
{
string senderName = "anonymous";
if (mi != null && mi.sender != null)
{
if (!string.IsNullOrEmpty(mi.sender.name))
{
senderName = mi.sender.name;
}
else
{
senderName = "player " + mi.sender.ID;
}
}
this.messages.Add(senderName +": " + newLine);
}
Your answer

Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Trigger player movement on touch 1 Answer