x


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?

more ▼

asked Apr 22, 2010 at 10:03 AM

Pria gravatar image

Pria
13 10 8 12

Can you provide an extended version of the code? I'm trying to do just that and having a bit of trouble :)

Mar 04, 2013 at 09:14 PM Hesta
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Apr 23, 2010 at 08:49 AM

Pria gravatar image

Pria
13 10 8 12

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 22, 2010 at 10:33 AM

Novodantis 1 gravatar image

Novodantis 1
1.8k 28 34 56

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7227
x1290
x103

asked: Apr 22, 2010 at 10:03 AM

Seen: 1744 times

Last Updated: Mar 04, 2013 at 09:14 PM