Link to the object in the scene?

I would like to be able to get a link to the object in the scene, something like you can get in google maps for certain location…that link should open the web build and show only that certain object. I see there are lot of problems that should be solved to make this working. Any ideas about what is the best course of action?

Thanks!

unity forums cross post:http://forum.unity3d.com/threads/93736-Link-to-the-object-in-the-scene?p=608754#post608754

Like Fox already mentioned i would do it completely in Unity so it doesn’t require you to have php support on your webserver.

I guess you use UnityScript?

function QueryURIParameters()
{
    Application.ExternalEval(
        "var unity = unityObject.getObjectById(\"UnityContent\");" +
        "unity.SendMessage(\"" + gameObject.name +"\", \"OnURIParameters\", window.location.search);"
    );
}

function OnURIParameters(parameters : String)
{
    parameters = WWW.UnEscapeURL(parameters.Substring(1)); // strip the first character (it's the "?") and unescape the string
    var params : String[] = parameters.Split("&"[0]);
    for (var P : String in params)
    {
        Debug.Log(P);
        // Do what you want with the parameters
    }
}

function Start()
{
    QueryURIParameters();
}

If your webpage has been opened like this:

http://my.domain.name/myunitypage.html?Param1=42&Param2=Blah

You will get this output in Unity:

Param1=42
Param2=Blah

Just make sure the GameObject this script is attached to has a unique name.


edit

I’ve just tested the code and it works. I had to do some changes. I’m not sure if the docs about browser communication are up-to-date. I’m still using Unity 3.0 and my embed code calls the div “unityPlayer” instead of “UnityContent”. There’s even a public inline function called “GetUnity” in the html template. It will return the unityobject. So you could do:

function QueryURIParameters()
{
    Application.ExternalEval(
        "GetUnity().SendMessage(\"" + gameObject.name +"\", \"OnURIParameters\", window.location.search);"
    );
}