use WWW and yield for send a variable to a url in c#

how can i use WWW and yield for send a variable to a url in c# , this is my code but it doesn't work

    using UnityEngine;
using System.Collections;

public class score : MonoBehaviour {
    public string addScoreUrl="http://localhost/game/addscore.php?";
    public string highscoreUrl = "http://localhost/game/display.php";
    string highscore_url;
    void Start () {
    postScore("sssssss", 1);

    // Update is called once per frame
    void Update () {

    void postScore(string name, int score)
        string highscore_url = addScoreUrl + "name=" + WWW.EscapeURL(name) + "&score=" + score;
        //WWW hs_post = new WWW(highscore_url); 

    IEnumerator wait()
        yield return new WWW(highscore_url);


Update - just saw one major problem - you declare highscore_url twice - so you are not changing the one that's being called by wait(). Either remove the second declaration, or pass it as a parameter to wait().

Otherwise... maybe the problem is in the receiving end - how sure are you that part works?

One way to test it would be to simplify your code:

void Start() {
    string testScoreUrl="http://localhost/game/addscore.php?name=foo&score=123";

See if you're correctly calling the URL and it's receiving the parameters. If not, then you need to fix addscore.php

If it is working, then change the above code a line at a time - first move it to a separate function, then make it a coroutine, etc, checking each step of the way that it's still working.

This is kind of a duplicate question of this (although you've done well to make a good start on it):

PHP can accept data either as a GET request (using $_GET), or a POST request (using $_POST), or you can program it to accept either, using the more general ($_REQUEST) variable - which contains the values from either type.

The reason I mention this is that you might be better off making a POST request, since they are specifically designed to have variables added, and you don't end up with a long sprawling URL string. It's also good practice because there is sometimes a hard limit to the length of this string, so if you end up needing to append even more data, you can hit this limit fairly quickly.

So, taking the code from my answer of that, and matching it to your variables, you'd end up with something which looks like this:

(this won't work if your PHP specifically uses $_GET - but if that's what you have, just change your $_GET to $_REQUEST)

using UnityEngine;

public class Scores : MonoBehaviour {

    void Start() {

        PostScore("duck", 999999);


    void PostScore(string name, int score) {

        string url = "http://localhost/game/addscore.php";

        WWWForm form = new WWWForm();
        form.AddField("name", name);
        form.AddField("score", score.ToString() );
        WWW www = new WWW(url, form);


    IEnumerator WaitForRequest(WWW www)
        yield return www

        // check for errors
        if (www.error == null)
            Debug.Log("WWW Ok! - result: " +;
        } else {
            Debug.Log("WWW Error: "+ www.error);

(It's also worth noting that as soon as you roll this out for public consumption, you'll need to protect your score submissions by adding a hash key, so that it's harder for users to spoof calls to your scoreboard! - but I guess that's a topic for another question!)