I’ve read all the documentation here:
http://unity3d.com/support/documentation/Manual/Web%20Player%20Deployment.html
and I’ve searched for help, but found none of satisfaction.
My request is simple. I want to pick out some arguments from the html and send them to unity. For example:
http://foo.com/loadgame.php?myvar=mytest
Then in the php file, i can extract the value of myvar, echo some javascript, for instance:
var unity = unityObject.getObjectById("UnityContent");
unity.SendMessage("MyClass", "SetVar", "mytest");
…but it just doesn’t work.
I want this myvar into my unity game, but how exactly?
The Unity Web Player and browser communication will be your greatest reference.
In the web page code, you will need to add some information to it. As below.
<script>
var unity = unityObject.getObjectById("UnityContent");
</script>
<input type="button" value="Press Me" onClick="unity.SendMessage('GUI', 'ChangeText', 'Hello from a web page!');"/>
So this says, that in Unity, we are looking for an object named “GUI” That object has a script attached to it. The name of the script is not important. That script then has to have a function called “ChangeText” that accepts a String variable.
var MyText : String="Hello World!";
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), MyText);
if (GUI.Button(Rect(10,35,50,20),"Set Text"))
MyText="Hello World!";
}
function ChangeText(str : String){
MyText=str;
}
Hi and thanks for the effort BigMisterB. However, it’s a little off from what I wanted here. Your example code I fully understand, but it is not what I am seeking here
Like I said, I already read that page you linked to, and all under that section. Nothing there (by example) tells of getting parameters from the url to the game.
For example, if I want to link to my game and add some parameters in the url to use in the game. That is what I actually need.
I’m thinking SendMessage from javascript needs to be run after the app is loaded, but how to do it?
After a lot of more reading and trial and error I managed to solve this with PHP and Application.srcValue. I documented my result here:
http://answers.unity3d.com/questions/5220/how-can-you-send-variables-to-unity3d-from-the-url
Is this valid for unity 3 ? cause I can’t make it work, only works for web publishing in Unity 2.6
worked fine for me in 3.2 a month or so ago. 
I’ve been looking for this myself too and it took a bit of googling and experimenting, but I found a way to do this very easily, and without having to adjust the HTML file (which is convenient, especially if you have no other reasons to modify the HTML file).
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
Simply add it to any GameObject in your scene, and call the string GetValue(string key) method.
2 Likes
bernardfrancois you are 3 years late
I know; found this thread as I was looking for a canned solution myself but didn’t find one.
I don’t think my reply will still be useful for the people higher in the thread, but others looking for a solution may end up in this thread and find it useful.
Happy New Year 
Thanks Bernard, exactly what I was looking for!