I have this code for accessing a database to pull question information for our game. The code works in the editor and in PC builds, however mobile and web builds do not. I am new to both mobile and database programming so I am not sure where the hangups are. Any tips or advice is greatly appreciated.
using UnityEngine;
using System.Collections;
namespace QuestionStuff
{
public class Question : MonoBehaviour
{
private string formRandomizer = "1";
private string questionURL = "www.g2the3rd.com/questiongrabber.php";
private string hash = "5f9901fc60b769b523d0dd8e79b3fe08";
private string question, answerone, answertwo, answerthree, answerfour, answerfive, answersix, correct;
public Question ()
{
this.question = "";
this.answerone = "";
this.answerthree = "";
this.answerfour = "";
this.answerfive = "";
this.answersix = "";
this.correct = "";
}
public void GenerateQuestion ()
{
char[] delimiters = new char[1];
delimiters [0] = char.Parse ("$");
WWWForm questionForm = new WWWForm ();
questionForm.AddField ("myform_hash", hash);
int newRandomQuestion = Random.Range (1, int.Parse (formRandomizer));
formRandomizer = newRandomQuestion.ToString ();
questionForm.AddField ("myform_randomizer", newRandomQuestion);
WWW getQuestion = new WWW (questionURL, questionForm);
while (!getQuestion.isDone) {
Debug.Log (Time.time);
}
string[] data = getQuestion.text.Split (delimiters);
this.question = data [0];
this.answerone = data [1];
this.answertwo = data [2];
this.answerthree = data [3];
this.answerfour = data [4];
this.answerfive = data [5];
this.answersix = data [6];
this.correct = data [7];
}
public string GetQuestion(){
return this.question;
}
public string GetCorrectAnswer(){
return this.correct;
}
public string GetAnswer(int answerNumber){
switch(answerNumber){
case 1:
return this.answerone;
case 2:
return this.answertwo;
case 3:
return this.answerthree;
case 4:
return this.answerfour;
case 5:
return this.answerfive;
case 6:
return this.answersix;
default:
return "Invalid number.";
}
}
}
}