Player names and scoreboard not working...
Options
Hi, Can anyone point me in the direction of a working multiplayer scoreboard tutorial that works with photon? I've been trying to figure out how to do it myself but here are the problems:
1: In the levels I've got an empty game object that lists who spawned and then it instantiates a prefab containing the payers name and points (on start for now). The problem is that it somehow reverses the names of the players so that if there's 2 players, one called left and one called right, the names are switched. Why? here's my code:
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
GameObject go = PhotonNetwork.Instantiate(PSEntry.name, transform.position, Quaternion.identity, 0);
go.transform.SetParent(this.transform);
go.transform.Find("Username").GetComponent<Text>().text = p.NickName;
go.transform.Find("Points").GetComponent<Text>().text = "22222";
}
- the switching of the names is also a problem when I try and display each players names over their heads with this code:
if (pv.isMine)
{
GetComponentInChildren<TMP_Text>().text = "" + PhotonNetwork.playerName;
canvasNames.transform.Rotate(0, 180, 0);
}
if (!pv.isMine)
{
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
GetComponentInChildren<TMP_Text>().text = "" + p.NickName;
canvasNames.transform.Rotate(0, 180, 0);
}
}
*pv is photonView assigned in the inspector.
Why is it switching the names and how do I make it work?
2: if I put on each of my player on awake to acces the instantiated players Game Object so that I can check if their dead via their health script: photonView.owner.TagObject = gameObject;
and then use this in the empty GO in the level that lists the players:
GameObject go1 = (GameObject)PhotonNetwork.player.TagObject;
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
if (go1.GetComponentInParent<Health>().dead1True)
{
//Instantiate the PlayerScoreEntry prefab (PSEnty.name) if the player is dead.
GameObject go = PhotonNetwork.Instantiate(PSEntry.name, transform.position, Quaternion.identity, 0);
go.transform.SetParent(this.transform);
go.transform.Find("Username").GetComponent<Text>().text = p.NickName;
go.transform.Find("Points").GetComponent<Text>().text = "922222";
}
}
It doesn't show up for anyone else but the person who died even though it's photon network instantiated?
1: In the levels I've got an empty game object that lists who spawned and then it instantiates a prefab containing the payers name and points (on start for now). The problem is that it somehow reverses the names of the players so that if there's 2 players, one called left and one called right, the names are switched. Why? here's my code:
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
GameObject go = PhotonNetwork.Instantiate(PSEntry.name, transform.position, Quaternion.identity, 0);
go.transform.SetParent(this.transform);
go.transform.Find("Username").GetComponent<Text>().text = p.NickName;
go.transform.Find("Points").GetComponent<Text>().text = "22222";
}
- the switching of the names is also a problem when I try and display each players names over their heads with this code:
if (pv.isMine)
{
GetComponentInChildren<TMP_Text>().text = "" + PhotonNetwork.playerName;
canvasNames.transform.Rotate(0, 180, 0);
}
if (!pv.isMine)
{
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
GetComponentInChildren<TMP_Text>().text = "" + p.NickName;
canvasNames.transform.Rotate(0, 180, 0);
}
}
*pv is photonView assigned in the inspector.
Why is it switching the names and how do I make it work?
2: if I put on each of my player on awake to acces the instantiated players Game Object so that I can check if their dead via their health script: photonView.owner.TagObject = gameObject;
and then use this in the empty GO in the level that lists the players:
GameObject go1 = (GameObject)PhotonNetwork.player.TagObject;
foreach (PhotonPlayer p in PhotonNetwork.playerList)
{
string nickName = p.NickName;
if (go1.GetComponentInParent<Health>().dead1True)
{
//Instantiate the PlayerScoreEntry prefab (PSEnty.name) if the player is dead.
GameObject go = PhotonNetwork.Instantiate(PSEntry.name, transform.position, Quaternion.identity, 0);
go.transform.SetParent(this.transform);
go.transform.Find("Username").GetComponent<Text>().text = p.NickName;
go.transform.Find("Points").GetComponent<Text>().text = "922222";
}
}
It doesn't show up for anyone else but the person who died even though it's photon network instantiated?
0