doulu8341 2019-04-03 09:03
浏览 473

Unity3d - 运行php代码的UnityWebRequest

I have a php file which will increase a counter in a database. I want it so that I can increase the counter from inside the C# script in Unity3d. Is there a way of updating the database by calling the php script from C#?

I've checked the Unity documentation for UnityWebRequest and nothing is to do with simply 'opening' a url (without opening in the browser) or updating a database. I tried using UnityWebRequest and also the now obselete WWW but haven't got either of them to work.

I can't actually upload any code at the moment because the server I'm using is down, but I'll do it as soon as it's back online. (This isn't the reason nothing seems to be working.)

  • 写回答

2条回答

  • drt41563 2019-04-03 09:45
    关注

    Use a simple web request to your get page in php.

    you can also build your url with parameters if you need aditional functionality

        IEnumerator GetRequest(string uri)
        {
            //http://localhost:3000/ if you are executing on same machine
            using (UnityWebRequest webRequest = UnityWebRequest.Get("www.yoursite.com/increaseCounter"))
            {
                // Request and wait for the desired page.
                yield return webRequest.SendWebRequest();
    
                if (webRequest.isNetworkError)
                {
                   //check errors
                }
                else
                {
                   //all ok
                }
            }
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题