Pass arguments to and from unity application

I make an HTML page that contain a unity object “after build for web” and I need to pass some parameters from the HTML page to the unity object.

thank you

you can do that through javascript in your html.

I try to do that but never worked
what I do is like:

document.write(myArgument,HTMLArgument);

that will not work

You can call functions from Unity from the html java script and call specific functions from the page from unity

there is an example on how to communicate from html to the unity plugin and back

the most important thing to keep in mind is that the unity plugin is executed client side, not server side (just to be sure, as this missassumption is a common error with paths sent to the unity plugin as some server relative paths will not work, you need to pass the full http url)

in html page

<script language="JavaScript" type="text/javascript">
<!--
// Using the above call from Unity, this will receive
// "Hello from Unity!" as the argument.
function MyFunction2( arg )
{
alert( arg );
}
-->
</script>

Application.ExternalCall ("MyFunction2", "Hello from Unity!");

or you could just read the documentation on this… :slight_smile:

file:///Applications/Unity/Unity.app/Contents/Documentation/Documentation/ScriptReference/Application.ExternalCall.html

also since it is file It might not work if that is not where your documentation is but then just search Apllication.ExternalCall. Good Luck :slight_smile:

If you want to pass data into your Unity application you can use either of these techniques:

  • Use the Unity Web Player’s ability to have bi-directional communication with browser-based JavaScript.

  • Write your custom data as parameters appended to your content’s src URL, then parse that out when your content loads.

For data you “know” when creating the page the second option can be dead simple. For example, instead of just supplying a src URL like “myfile.unity3d” in the object/embed tags, supply a src URL like “myfile.unity3d?name=value” like you would for any URL with parameters. Then inside your content you can get the src value via Applicaion.srcValue and parse out everything after the ? and do what you want with it.