查看: 841|回复: 0
打印 上一主题 下一主题

[其他] Unity连接Php的代码

[复制链接]

2317

主题

54

听众

2万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
20645
精华
62

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2015-2-26 13:29:53 |只看该作者 |倒序浏览

Unity连接Php的代码
  1. function Login() {

  2. var form = new WWWForm(); //创建一个WWWForm对象。

  3. form.AddField( “myform_hash”, hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file

  4. form.AddField( “myform_nick”, formNick );

  5. form.AddField( “myform_pass”, formPassword );

  6. var w = WWW(URL, form); //here we create a var called 'w' and we sync with our URL and the form

  7. yield w; //we wait for the form to check the PHP file, so our game dont just hang

  8. if (w.error != null) {

  9. print(w.error); //if there is an error, tell us

  10. } else {

  11. var return_data=w.data;

  12. if(return_data==“success”){

  13. Application.ExternalEval(“window.location.href='game.php?username=”+formNick+“‘”);

  14. }else if(return_data==“npe”){

  15. print(“Test ok”);

  16. formText = “用户名或密码不能为空!”; //here we return the data our PHP told us

  17. }else if(return_data==“nfn”){

  18. formText=“用户名不存在!”;

  19. }else if(return_data==“npw”){

  20. formText=“用户名或密码不正确!”;

  21. }

  22. w.Dispose(); //clear our form in game

  23. }

  24. formNick = “”; //just clean our variables

  25. formPassword = “”;

  26. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-8-5 16:57 , Processed in 0.204177 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部