Logo 3.5Cats_AndHalfAFish


Q & A : Web Player build.

August 10, 2014 reaching for the stars, Unity web games
Publishing with Unity.

Q : Why is my spotlight not working in the Web Player build ?

Well. There is a setting in the Unity editor that is very easy to overlook. It is hiding in this location : Edit > Project Settings > Quality.

Web Player : spotlight not working.

You have to click the downward arrow next to 'Default', in the column of the Web Player.
I have changed the default setting to 'Good' and set the 'Pixel Light Count' to 3.

Q : How do I incorporate the Web Player build into my website ?

The easiest thing to do, is to just copy all files inside the generated 'web' folder into your project. Next, copy the contents of the 'web.html' file into your own web page.

Building & incorporating into my website.
If you want, you can keep these files in a subfolder, as long as you take care to change the paths! One thing I wanted to do, but have not been able to figure out yet, is to also put the web.unity3d file into that subfolder ...


Q : How do I disable resizing of the game on the web page ?

You do this by chosing the right template when you build your game : 'File' > 'Build Settings' > 'Player Settings' > 'Resolution & Presentation' :

Disabling the context menu.
This option ('No Context Menu') disables right-clicking on the Unity plugin. So, no resizing (no full screen).


But. You can still zoom the web page (Ctrl +) & that really messes up labels & buttons ...

So, to fix that, you use your good old friend 'GUI.matrix'.
I found a really clean & easy way to do this on the site of Ben Silvis :

public static void AutoResize(int screenWidthDesign, int screenHeightDesign) {
    Vector2 resizeRatio = new Vector2((float)Screen.width / screenWidthDesign, 
                                        (float)Screen.height / screenHeightDesign);
    GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, 
                                new Vector3(resizeRatio.x, resizeRatio.y, 1.0f)); }   

void OnGUI() {
AutoResize(450, 600); // size used during design of game
/*the rest of your code*/ } 

Q : Optimizing the build ?

Something interesting : when you import an image into the Unity editor, you will see 2 dropdown buttons. One says 'Max Size', the other one 'Format'.

Optimizing textures.

'Format' has the options : 'compressed', '16 bits', and 'truecolor'.
The Unity documentation says that you can change the format to something that is 'not compressed' to work faster in the editor. But. Unity will still compress your textures when it builds !

To optimize your build, you should zoom in (scene view) & play with the 'max size' settings. You should lower the settings until you start seeing fuzziness. Then go one setting back up.