Author Topic: Change name of transforms/gameobjects in hierarchy  (Read 1885 times)

Gravitox

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Change name of transforms/gameobjects in hierarchy
« on: June 20, 2015, 04:18:17 PM »
Hi

I try to extend the "from scratch" example so that the GameObjects that represents the players in the hierarchy show the/change to the playerName which I added to the Gameplayer script. For testing the playerName is hardcoded.

All I have achieved is that either all GameObjects gets the same name or at least one GameObjects name is "Player (Clone)".

I have tried to change the name by using...
  1. TNManager.playerName = playerName;
...and react on it in...
  1. OnNetworkPlayerRenamed(Player p, string prevName) {
  2.     transform.name = p.name
  3. }
...but this changes all names of the GameObjects to the same.

I also tried to change the name on creation by...
  1. tno.Send(3, Target.AllSaved, playerName);
  1. [RFC(3)]
  2. void OnSetPlayerName(string name)  {
  3.         transform.name = name;
  4. }
...with the same result as above.

In every build I changed the hardcoded playerName in the GamePlayer script.

What am I doing wrong? How do I change the GameObject names right?^


Thanks for reading!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Change name of transforms/gameobjects in hierarchy
« Reply #1 on: June 21, 2015, 09:36:02 PM »
OnNetworkPlayerRenamed gets called on all clients. You need to check -- is this my player? If so, then rename. You aren't checking anything. Same with RFC.

Add a simple check:
  1. if (tno.isMine) transform.name = name;