Hello!
I use PUN and DB in my game.
I parse nicknames from DB via PHP, and write values in variable “namechar”.
After I replaced value “PhotonNetwork.playerName”.
I am not aware of a bug that will reset the playerName to “”. It might be in your code or something I didn’t notice yet.
You should check all usages of PhotonNetwork.playerName and see if you set it in some code that might run more than once (Start(), Awake() or similar).
Ok.
I fully tested to get the values of PHP, it turned out that the values are not empty only within IEnumerator. Here’s the code IEnumerator and variables.
public static string namechar;
public static string goldchar;
public static string hpchar;
public static string mpchar;
public static float xpos;
public static float ypos;
public static float zpos;
public static string acc_id;
public static string char_id;
IEnumerator HandleLogin(string login, string password) {
WWWForm form = new WWWForm();
form.AddField("mylogin", login);
form.AddField("mypassword", password);
WWW Login = new WWW(url, form);
yield return Login;
string a = Login.text; //get echo from php
string[] all = a.Split('|');
namechar = all[1];
goldchar = all[2];
hpchar = all[3];
mpchar = all[4];
xpos = float.Parse(all[5]);
ypos = float.Parse(all[6]);
zpos = float.Parse(all[7]);
acc_id = all[8];
char_id = all[9];
print(a);
if (all[0] == "Ok") {
LogIn = false;
chooseChar = true;
}
}
I think I understood why PhotonNetwork.playerName variable to the empty string. The fact that the variable PhotonNetwork.playerName created before the database will record data in a variable after entering the username and password. It remains to understand how to fix it.
You might want to take a look at Photon’s “Custom Authentication” feature. It allows you to use Photon API to authenticate a user and will encrypt username and password from client to server.
More about that:
On the other hand: As this is working for you now, there is no need to change a running system