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 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)