Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
I recently looked into getting url variables in unity webplayer, I got the full url including parameters form javascript and parsed it in C#, but now in flash I cant call javascript, so how can I get url variables such as UnityGame.html?variable =1

Thanks
Posted
Comments
Dholakiya Ankit 22-Jul-13 0:13am    
nice q but i have no answer dude should be rated 5..

1 solution

This way can be used to pass parameters into unity webplayer

Get URL parameters and assign to Use_id->


JavaScript
<script type="text/javascript">
<!--//initializing the WebPlayer

var u = new UnityObject2();
u.initPlugin(jQuery("#unityPlayer")[0], "Example.unity3d");


var GET = {};
var query = window.location.search.substring(1).split("&");
for (var i = 0, max = query.length; i < max; i++)
{
    if (query[i] === "") // check for trailing & with no param
        continue;

    var param = query[i].split("=");
    GET[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || "");
}
</script>


Inside html page ->

function OnUnityReady()
{

    u.getUnity().SendMessage("GameObject", "myTest", GET.Use_id);
}


Inside unity3D C# code ->

void Start()

{

Application.ExternalCall("OnUnityReady");

}



when you pass parameters into URL, pass like this :
www.mywebsite.com/abc.html?Use_id=xxxx -->
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900