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

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler