Read your own url posts in Webplayer

Hi,

I would like to ask you how i can read the posts of my own url in a web player game.
Exactly, i mean:
i have and “index.php?game=mygame” where is attached the game that i built and runs when i call that url.
I need to read the value of the variable “game” of the url in every load of the game.

Is there any csharp code example or how i can make it ?

thank you in advance

Hi,

There’s no way to do this directly, but the value is visible to Javascript running in the webpage containing your Webplayer game. You can use Application.ExternalCall to request it from Javascript, and use the browser-to-Unity communication path to send the full URL back into Unity.

I’ve attached a small example, which uses the following C# script and Javascript snippet to accomplish this, and show the URL via a Unity 4.6 UI.Text component. The built webplayer app can be found in the /build/ subfolder.

If you’re using Unity’s generated HTML file to view your webplayer game, you’ll have to either create a custom webplayer page template or manually add the Javascript snippet to the Unity-generated HTML file each time you build.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

[RequireComponent(typeof(Text))]
public class URLChecker : MonoBehaviour {

    private Text text;
    private string fmt = "full url: {0}";

    // Use this for initialization
    void Start () {
        text = GetComponent<Text>();
        text.text = "Loading...";
        Application.ExternalCall ("GetFullUrl", gameObject.name);
    }

    public void SetFullUrl(string fullUrl) {
        text.text = string.Format (fmt, fullUrl);
    }
}
function GetFullUrl(gameObjectName) {
    u.getUnity().SendMessage(gameObjectName, "SetFullUrl", window.location.href);
}

1865868–119798–Example.zip (109 KB)