need help with player nicknames.
Options
atrupb
✭
using UnityEngine;
using UnityEngine.UI;
public class save_names : MonoBehaviour
{
public static save_names save_Names;
public InputField name;
public string namey;
private void Awake()
{
if (save_Names == null)
{
save_Names = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(gameObject);
}
private void Update()
{
if (namey != name.text)
{
namey = name.text;
}
}
}
is one script and
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class playerNameScript : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
photonView.RPC("playerNameMethod", RpcTarget.All);
}
// Update is called once per frame
void Update()
{
}
[PunRPC]
void playerNameMethod()
{
PhotonNetwork.LocalPlayer.NickName = save_names.save_Names.namey;
GetComponentInChildren<TMPro.TextMeshPro>().text = PhotonNetwork.LocalPlayer.NickName;
}
}
is the other script.
Here's the problem: lets say we have user that names himself "koroo". he presses start and in-game everyone else is also named "koroo". how can i make it so that player names are properly synced?
using UnityEngine.UI;
public class save_names : MonoBehaviour
{
public static save_names save_Names;
public InputField name;
public string namey;
private void Awake()
{
if (save_Names == null)
{
save_Names = this;
DontDestroyOnLoad(gameObject);
}
else Destroy(gameObject);
}
private void Update()
{
if (namey != name.text)
{
namey = name.text;
}
}
}
is one script and
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class playerNameScript : MonoBehaviourPunCallbacks
{
// Start is called before the first frame update
void Start()
{
photonView.RPC("playerNameMethod", RpcTarget.All);
}
// Update is called once per frame
void Update()
{
}
[PunRPC]
void playerNameMethod()
{
PhotonNetwork.LocalPlayer.NickName = save_names.save_Names.namey;
GetComponentInChildren<TMPro.TextMeshPro>().text = PhotonNetwork.LocalPlayer.NickName;
}
}
is the other script.
Here's the problem: lets say we have user that names himself "koroo". he presses start and in-game everyone else is also named "koroo". how can i make it so that player names are properly synced?
0
Comments
-
Fixed. If curious how:
I changed
GetComponentInChildren<TMPro.TextMeshPro>().text = PhotonNetwork.LocalPlayer.NickName;
to
GetComponentInChildren<TMPro.TextMeshPro>().text = this.photonView.Owner.NickName;0