Reputation: 3136
I'm planning to send a integer value to CallUpdatePlayerName after SetPlayerName is called is this possible? Below is my code
[SyncVar(hook = nameof(CallUpdatePlayerName))]
public string playerName;
[Command]
public void SetPlayerName(string value)
{
if (isLocalPlayer)
{
playerName = value;
}
}
private void CallUpdatePlayerName(string oldPlayerName, string newPlayerName, int index)
{
}
Upvotes: 0
Views: 464
Reputation: 90714
No you can't, not like this.
In such case don't use a SyncVar
at all but rather something like e.g.
public void SetPlayerName(string name)
{
if(!isLocalPlayer) return;
playerName = name;
// Tell the host
CmdSetPlayerName(name, yourIndex);
}
[Command]
private void CmdSetPlayerName (string name, int index)
{
playerName = name;
// Forward to all other clients
RpcSetPlayerName(name, index):
}
[ClientRpc]
private void RpcSetPlayerName (string name, int index)
{
playerName = name;
}
Upvotes: 1