- Home /
PlayerName in Chat Window
I am adding the chat functionality in my Unity game. I am asking the username along with the IP address and Port number.
static var userName : String = "Player";
function OnGUI ()
{
if (Network.peerType == NetworkPeerType.Disconnected){
userName = GUILayout.TextField(userName);
....
}else{...}
Now when I click on Connect to Server, it takes the default value of username instead of the current value written in the TextField.
And when I disconnect and then reconnect it will take the previous value written in the TextField. So as a result it always takes the previous value that was written in the TextField instead of the current one.
Can anyone please point out my mistake?
Can you provide an extended version of the code? I'm trying to do just that and having a bit of trouble :)
Answer by Pria · Apr 23, 2010 at 08:49 AM
I found the solution.
I was previously retrieving the player's name in Awake() in Chat script. After putting the player name retrieval code in Update(), it is working.
Answer by Novodantis 1 · Apr 22, 2010 at 10:33 AM
Would it not be better to assign the userName value from the text field when the player clicks Connect, as opposed to the whole time they are disconnected? I don't know, might need a little more detail still.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Unity/Photon chat system error. 1 Answer
Lidgren Network in Unity Web Player 1 Answer
Multiplayer in Action RPG, best approach? 2 Answers
Unity UNET Multiplayer Chatroom - (Need Help With 1 Line) 1 Answer