Author Topic: Change player name in OnNetworkConnect or near.  (Read 2192 times)

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Change player name in OnNetworkConnect or near.
« on: November 11, 2013, 06:56:10 AM »
Hey! i got a script so when he connects to the server it calls "OnNetworkConnect", and that works just fine. But then i want to change the player name in that function, and apparently that wont work
  1.  
  2. void OnNetworkConnect(bool succes, string message){
  3.         if(succes){
  4.                 Debug.Log("Playername before: " + TNManager.playerName);
  5.                 TNManager.playerName = "ChangedName";
  6.                 Debug.Log("Playername after: " + TNManager.playerName);
  7.                 loadMenu();
  8.         }
  9.         else{
  10.                 Debug.Log("there was an error: " + message);
  11.                 onFailedConnection();
  12.         }
  13. }
  14.  
The name is both Guest before and after the change.
Ive also tested making the name change upon start in the menu that loads
  1.  
  2. void Start(){
  3.         Debug.Log(TNManager.playerName);
  4.         TNManager.playerName = "ChangedName";
  5.         Debug.Log(TNManager.playerName);
  6. }
  7.  
And both here returns Guest.
Then i tested making an Coroutine with a delay by 0.1 seconds, then change the name(in the start function of the menu), Then it works just fine! Is it really neccisary to have a delay for changing name of the player?

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Change player name in OnNetworkConnect or near.
« Reply #1 on: November 11, 2013, 07:47:43 AM »
I noticed that the tnmanager.playername doesn't change immidiatly as i write. So it changes, just not right away!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change player name in OnNetworkConnect or near.
« Reply #2 on: November 11, 2013, 12:10:17 PM »
The change needs to go through the server as it's a synchronized call.