unity www php,使用C#调用php脚本(Unity)

我对Unity和PHP都还不是很陌生,并且我目前正在一个项目中,可以使用PHP将数据从MySQL数据库解析到Unity.

最初,我想尝试启用一种方法,使用户可以更改php脚本并使其选择不同的数据表,但是我被告知最好列出php脚本中的所有变量并从中调用它可能更安全.相应地团结;

Display.php的

$table = mysql_real_escape_string($_GET['table'], $db);

if ($table == "shoes") {

$query = "SELECT * FROM `shoes` ORDER by `price` ASC LIMIT 10";

elseif ($table == "sneakers") {

$query = "SELECT * FROM `sneakers` ORDER by `price` ASC LIMIT 10";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$num_results = mysql_num_rows($result);

for($i = 0; $i < $num_results; $i++)

{

$row = mysql_fetch_array($result);

echo $row['shopname'] . "" . $row['price'] . "

";

}

我在调用php并选择要选择的表时遇到了麻烦,对此我还很陌生,因此,如果这对您来说似乎完全不合适,我深表歉意.

这是我的Unity脚本;

HSController.cs

void Start()

{

StartCoroutine(GetScores());

}

// remember to use StartCoroutine when calling this function!

IEnumerator PostScores(string name, int score)

{

string hash = Md5Sum(name + score + secretKey);

string post_url = addScoreURL + "name=" + WWW.EscapeURL(name) + "&score=" + score + "&hash=" + hash;

WWW hs_post = new WWW(post_url);

yield return hs_post; // Wait until the download is done

if (hs_post.error != null)

{

print("There was an error posting the high score: " + hs_post.error);

}

}

IEnumerator GetScores()

{

gameObject.guiText.text = "Loading...";

WWW hs_get = new WWW(highscoreURL);

yield return hs_get;

if (hs_get.error != null)

{

print("There was an error getting the high score: " + hs_get.error);

}

else

{

gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.

}

}

任何帮助或朝着正确方向发展的观点都将非常棒!

亲切的问候

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值