Hello!
I want to achieve this…
So in the offline scene players choose what would they like their name to be, name gets saved to PlayerPrefs.
Then when player connects, I want to pull that name from PlayerPrefs and set it to his Text which is child of Canvas which is child of the player.
How would I go about doing that?
TehGM
2
Send that name upon connectiong or server’s request in network message or a command.
How would I exactly do that?
The only thing I managed to come up with so it kinda works (has tons of bugs when the player disconnects) is this:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityEngine.UI;
public class Player_Name : NetworkBehaviour {
public string playerName;
public override void OnStartLocalPlayer(){
playerName = PlayerPrefs.GetString("Name");
InvokeRepeating("InvokableFunction",5f,5f);
}
[Command]
void CmdSendNameToServer(string nameToSend)
{
RpcSetPlayerName(nameToSend);
}
[ClientRpc]
void RpcSetPlayerName(string name)
{
gameObject.transform.FindChild("Canvas").transform.FindChild ("Text").GetComponent<Text>().text = name;
}
void InvokableFunction() {
CmdSendNameToServer(playerName);
}
void OnDestroy(){
CancelInvoke();
}
}
I presume this isn’t the right way to do it right?
Managed to do it, just instead of invoking it I put it in fixed update!