donglizuo8892 2016-07-19 04:54
浏览 107

Unity中的WWW返回空字符串

Its returning an empty string and I can't seem to figure out why, if you visit the page it outputs fine. (http://lgdev.site.nfoservers.com/getItems.php). I'm trying to get all the data, separate it by certain characters, then use the code in the game t operate it and sort it into the correct places. But like I said its returning an empty string instead of the data that's show on the webpage I gave above.

Game Code:

 public void loadItems()
 {
     WWWForm form = new WWWForm();
     WWW w = new WWW("http://lgdev.site.nfoservers.com/getItems.php", form);
     StartCoroutine(loadItemsFunc(w));
 }

 IEnumerator loadItemsFunc(WWW w)
 {
     yield return w;
     Debug.Log(w.text);
     string[] tmpdata1 = w.text.Split(char.Parse("="));
     foreach(string data in tmpdata1)
     {
         string[] tmpinfo = data.Split(char.Parse("~"));
         GameObject tmpObj = Instantiate(weapon);
         tmpObj.GetComponent<weapon>().name = tmpinfo[0];
         tmpObj.GetComponent<weapon>().vitalisim = int.Parse(tmpinfo[1]);
         tmpObj.GetComponent<weapon>().defence = int.Parse(tmpinfo[2]);
         tmpObj.GetComponent<weapon>().strength = int.Parse(tmpinfo[3]);
         string[] offsetInfo1 = tmpinfo[5].Split(char.Parse(";"));
         foreach (string off in offsetInfo1)
         {
             string[] offset = off.Split(char.Parse(","));
             tmpObj.GetComponent<weapon>().offsetsPos.Add(new Vector3(float.Parse(offset[0]), float.Parse(offset[1]), float.Parse(offset[2])));
             tmpObj.GetComponent<weapon>().offetsRot.Add(new Vector3(float.Parse(offset[3]), float.Parse(offset[4]), float.Parse(offset[5])));
             tmpObj.GetComponent<weapon>().offetsSize.Add(new Vector3(float.Parse(offset[6]), float.Parse(offset[7]), float.Parse(offset[8])));
         }
         string[] typeInfo = tmpinfo[4].Split(char.Parse(","));
         if (tmpinfo[1] == "SwordnShield")
         {
             tmpObj.GetComponent<weapon>().anim = swordAndShieldAnimSet;
         }
         else if (tmpinfo[1] == "TwoHanded")
         {
             tmpObj.GetComponent<weapon>().anim = twoHandedAnimSet;
         }
         foreach (string prefab in tmpinfo[6].Split(char.Parse(",")))
         {
             tmpObj.GetComponent<weapon>().prefabs.Add(prefab);
         }
     }

 }

PHP Code:

<?PHP
     $con = mysql_connect("localhost","user","passs") or ("Cannot connect!"  . mysql_error());
     if (!$con)
     die('Could not connect: ' . mysql_error());

     mysql_select_db("lgdev_projectzed" , $con) or die ("could not load the database" . mysql_error());
     $query = "SELECT * FROM `equipment`";
     $check = mysql_query($query) or die(mysql_error()." ".$query);
     if($check){
     }
     $numrows = mysql_num_rows($check);
     $text = "";
     while ($row = mysql_fetch_array($check, MYSQL_ASSOC)) {
         $text = $text."".$row["name"]."~".$row["vitalism"]."~".$row["defence"]."~".$row["strength"]."~".$row["type"]."~".$row["offsets"]."~". $row["prefabs"] ."=";
     }
     die($text);

 ?>

</div>
  • 写回答

1条回答 默认 最新

  • dsvyc66464 2016-07-19 06:10
    关注

    First, check if it gives any error with:

     Debug.Log(w.error); // place this before or after the other debug.log
    

    Since the form that you submit is empty, there is some error.. So check how to setup your form: https://docs.unity3d.com/ScriptReference/WWWForm.html

    If you don't need to post anything in the form, can use the plain WWW https://docs.unity3d.com/ScriptReference/WWW.html

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?