I am making an Android game, there is code to send highscore info to my web's PHP code.
Strange thing is, this works well in unity-editor, but after I make an .apk and run on real android phone, it does not work and gets errors.
Error is following (known by Eclipse logcat)
05-05 22:56:47.997: I/Unity(20561): NullReferenceException: Object reference not set to an instance of an object 05-05 22:56:47.997: I/Unity(20561): at HighScore.GetHash (System.String usedString) [0x00000] in :0 05-05 22:56:47.997: I/Unity(20561): at HighScore+c__Iterator14.MoveNext () [0x00000] in :0
Code is, function of registering nickname when firstly run highscore.
public IEnumerator RegisterName(string name)
{
string finalResult = "";
string tables = "";
for (int m = 0; m < difficultyModes.Length; m++)
{//Create a list of tables to send
if (m < difficultyModes.Length - 1)
{
tables += difficultyModes[m].databaseName + " ";
}
else
{
tables += difficultyModes[m].databaseName;
}
}
WWWForm rsFm = new WWWForm();
rsFm.AddField("name", name);
rsFm.AddField("tables", tables);
rsFm.AddField("hash", GetHash(name));
WWW rs = new WWW(registerUserURL, rsFm);
yield return rs;
Debug.Log(rs.text + " : " + difficultyModes[modeIndex].displayName);
finalResult = rs.text;
if (finalResult.Equals("Already Used"))
{
runningHsServer = 0;
status = "Name Already Used";
TitleScript.Instance.PopupMsgWithNoBack("Name is already taken.", true);
yield break;
}
else if (finalResult.Equals("Registration Complete"))
{//We Registered Now Update Score
PlayerPrefs.SetInt("nameRegistered", 1);
PlayerPrefs.SetString("registeredName", name);
TitleScript.Instance.PopupMsgWithNoBack("Name registered!", true);
TitleScript.Instance.PopupNo();
NewUI.Instance.myNick.text = name;
myNickName = name;
NewUI.Instance.OpenHigh();
}
else
{
runningHsServer = 0;
status = finalResult; yield break;
}
}
and GetHash part. (at here, NullReference error occurs)
string GetHash(string usedString)
{ //Create a Hash to send to server
MD5 md5 = MD5.Create();
//byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey); // this wrong because can't receive korean character
byte[] bytes = Encoding.UTF8.GetBytes(usedString + secretKey);
byte[] hash = md5.ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
GetHash
method?