Calling php script using C# (Unity)

前端 未结 1 1592
走了就别回头了
走了就别回头了 2021-01-16 22:03

I\'m fairly new to both Unity and PHP, and I am currently working on a project where I can parse data from a MySQL database to Unity, using PHP.

I initially wanted t

1条回答
  •  -上瘾入骨i
    2021-01-16 22:25

    Let me try to rewrite this into a working example:

    C#

    void Start() {
        StartCoroutine(GetData());
    }
    
    
    IEnumerator GetData() {
        gameObject.guiText.text = "Loading...";
        WWW www = new WWW("http://yoururl.com/yourphp.php?table=shoes"); //GET data is sent via the URL
    
        while(!www.isDone && string.IsNullOrEmpty(www.error)) {
            gameObject.guiText.text = "Loading... " + www.Progress.ToString("0%"); //Show progress
            yield return null;
        }
    
        if(string.IsNullOrEmpty(www.error)) gameObject.guiText.text = www.text;
        else Debug.LogWarning(www.error);
    }
    

    PHP

    
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题