I'm trying to make a one vs one game, but I am having trouble displaying both players names.
I have made a simple game scene, that launches only when 2 players are joined (min 2 players, max 2 players).
In the very beginning I want to have a UI panel (with text) displaying each of their names, which goes away after few seconds.
What would I need to do to accomplish this?
I've made a reference to the two text fields that I want replaced with the Photon.playerName of each player, but every time I try only one of the text fields gets filled with the right name (other is blank). I am quite new to online development, but The code I've written is as follows
private GameObject IntroductionPanel;
private Text Player1text;
private Text Player2text;
// few other variables
void Awake () {
IntroductionPanel.gameObject.SetActive (false);
playerID = PhotonNetwork.player.ID;
SpawnPlayers();
}
void SpawnPlayers () {
if (playerID == 1) {
player1 = (GameObject)PhotonNetwork.Instantiate (prefab.name, Player1Spawn.transform.position, Player1Spawn.transform.rotation, 0);
}
if (playerID == 2) {
player2 = (GameObject)PhotonNetwork.Instantiate (prefab.name, Player2Spawn.transform.position, Player2Spawn.transform.rotation, 0);
}
SetupIntroductionPanel ();
StartCoroutine (MoveMainCamera ());
}
void SetupIntroductionPanel () {
// set the players name here (Where I'm stuck)
if (playerID == 1) {
Player1text.text = PhotonNetwork.playerName;
}
if (playerID == 2) {
Player2text.text = PhotonNetwork.playerName;
}
IntroductionPanel.gameObject.SetActive (true);
}
IEnumerator MoveMainCamera () {
// move camera
}
The "SetupIntroductionPanel" function is where I try to do this.
Any help will be greatly appreciated! Thank you.
I have made a simple game scene, that launches only when 2 players are joined (min 2 players, max 2 players).
In the very beginning I want to have a UI panel (with text) displaying each of their names, which goes away after few seconds.
What would I need to do to accomplish this?
I've made a reference to the two text fields that I want replaced with the Photon.playerName of each player, but every time I try only one of the text fields gets filled with the right name (other is blank). I am quite new to online development, but The code I've written is as follows
private GameObject IntroductionPanel;
private Text Player1text;
private Text Player2text;
// few other variables
void Awake () {
IntroductionPanel.gameObject.SetActive (false);
playerID = PhotonNetwork.player.ID;
SpawnPlayers();
}
void SpawnPlayers () {
if (playerID == 1) {
player1 = (GameObject)PhotonNetwork.Instantiate (prefab.name, Player1Spawn.transform.position, Player1Spawn.transform.rotation, 0);
}
if (playerID == 2) {
player2 = (GameObject)PhotonNetwork.Instantiate (prefab.name, Player2Spawn.transform.position, Player2Spawn.transform.rotation, 0);
}
SetupIntroductionPanel ();
StartCoroutine (MoveMainCamera ());
}
void SetupIntroductionPanel () {
// set the players name here (Where I'm stuck)
if (playerID == 1) {
Player1text.text = PhotonNetwork.playerName;
}
if (playerID == 2) {
Player2text.text = PhotonNetwork.playerName;
}
IntroductionPanel.gameObject.SetActive (true);
}
IEnumerator MoveMainCamera () {
// move camera
}
The "SetupIntroductionPanel" function is where I try to do this.
Any help will be greatly appreciated! Thank you.