Hi there everybody! I’d like to know if there is a way to embed parameters inside the HTML, and to retrieve these parameters from an Unity script (very much like the Adobe Flash Player)
Thanks in advance!
Hi there everybody! I’d like to know if there is a way to embed parameters inside the HTML, and to retrieve these parameters from an Unity script (very much like the Adobe Flash Player)
Thanks in advance!
There is no simplified API to do this directly. You can, however use Application.absoluteURL to parse the embed URL. So you do something like this for the URL:
mygame.unity3d?somevalue=123&anothervalue=456
And then parse it using .NET string functions.
The other option is to pass in variables after the Unity content has started using the browser communication functions available.
Matthew, thanks for your reply. So, you are basically saying that I should send the parameters in a GET-like fashion, right? Ok, that should work, but I was thinking about a “param” tag inside the embed code, “a la” flash.
Yeah, you have to do GET-like parsing (which has its downsides, because changing the URL will invalidate any client cache).
Unity has no mechanism for passing things in via a FlashVars-like system.
Hi, Lorenzo - welcome to the forum!
Although you can’t access param tags directly, there is another possibility. The Application.ExternalCall function calls a JavaScript function in the host web page. You might be able to supply the parameters with a JS function - you could then call that function in Unity to get your data. This is not especially neat, but it would avoid the use of parameters in the URL, if that’s a problem.
Thanks ,andeee. Yes, I think that I’ll follow your advice (I’m currently reading the docs about Application.ExternalCall and Application.ExternalEval)
In case this would be useful for someone stumbling upon this post - it’s indeed possible to do this using ExternalCall, but it requires a bit of undocumented functionality.
For some reason, Application.AbsoluteURL or other values I get from the Unity API give me the URL without parameters.
I created a class RequestParameters.cs and made it available public domain on my company’s blog (as a little New Year’s present to the community :)):
previewlabs.com/reading-url-parmeters-from-web-player-builds
The article explains how it works.