I’m trying to get a Unity WebPlayer control to resize when the browser is resized. Here’s the code I think is pertinent:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
<!--
function GetUnity()
{
if (typeof unityObject != "undefined")
{
return unityObject.getObjectById("unityPlayer");
}
return null;
}
function ResizeUnity()
{
//This function properly assigns innerWidth and Height to winWidth and winHeight
GetWindowSize();
var unity = GetUnity();
if(unity != null)
{
//This does not properly resize anything at all
unity.width = winWidth;
unity.height = winHeight;
}
}
}
if (typeof unityObject != "undefined")
{
GetWindowSize();
unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", winWidth, winHeight, params);
}
-->
</script>
<style type="text/css">
<!--
div#unityPlayer {
cursor: default;
height: 100%;
width: 100%;
}
-->
</style>
</head>
<body margin="0" marginwidth="0" marginheight="0" scroll="no" onResize="ResizeUnity()">
<div class="content">
<div id="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
</a>
</div>
</div>
</div>
</body>
</html>
From various alert()
s in the code, I can verify that ResizeUnity()
is being called when I change the size of the window. I can verify that winWidth
and winHeight
are getting proper values assigned to them upon resizing. But, no matter what I do to the browser window, the Unity WebPlayer object stays the same size it was when it was loaded.
What am I doing wrong?