2

I'm ultimately trying to show active players, but I'm having trouble setting the value of a text box.

My understanding is that once a player joins, I need to use syncvars to show all player names on each client. So to start, I'm trying this...

[SyncVar(hook = "OnPlayerName")]
public string name;

void OnPlayerName(string newPlayerName)
{
    playerlist.text = name;

}

public override void OnStartClient()
{
    name = "terrance";
}

When I run this, the text box is empty. If I set the text without syncvars, it works. Of course, the change is only visible to the local client if I do it without syncvars.

RESOLUTION: the parameter newPlayerName needs to match the variable name, so in this case "name"...

void OnPlayerName(string name)
tintyethan
  • 1,772
  • 3
  • 20
  • 44

1 Answers1

2

You are hooking it to a function that doesnt exist,

"OnPlayName"

Should be

[SyncVar(hook = "OnPlayerName")]
public string name;
Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42