Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile a Unity3D game project from command line into WebGL?

Tags:

unity3d

I have achieved to compile it into Windows or Mac, but no luck with WebGL.

See my lines for

From Windows to Windows (place them in a .bat file)

set mypath=%cd%
@echo %mypath%
"C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -logFile stdout.log -projectPath %mypath% -buildWindowsPlayer "builds\mygame.exe"

From Linux to Windows (place them in a .sh file)

#/bin/bash
projectPath=`pwd`
xvfb-run --auto-servernum --server-args='-screen 0 1024x768x24:32' /opt/Unity/Editor/Unity -batchmode -nographics -logfile stdout.log -force-opengl -quit -projectPath ${projectPath} -buildWindowsPlayer "builds/mygame.exe"

From Windows or Linux to Mac: Replace -buildWindowsPlayer with -buildOSXPlayer and mygame.exe with mygame.app

However, I having troubles for WebGL. The documentation of Unity3D: https://docs.unity3d.com/Manual/CommandLineArguments.html does not provide any help

there is the command parameter -buildTarget webgl
but nothing happens with that.

HEEEEEEEELLLLLLLLLLLLLPPPPPPP !!!! :(

like image 207
Dimitrios Ververidis Avatar asked Jul 13 '17 13:07

Dimitrios Ververidis


1 Answers

Well, I found it.

Make a folder Assets/Editor,

and place the cs script in it:

using UnityEditor;
class WebGLBuilder {
    static void build() {

        // Place all your scenes here
        string[] scenes = {"Assets/scenes/S_MainMenu.unity", 
                            "Assets/scenes/S_Login.unity",
                            "Assets/scenes/S_Help.unity",
                            "Assets/scenes/S_1.unity",
                            "Assets/scenes/S_Reward.unity",
                            "Assets/scenes/S_Credits.unity",
                            "Assets/scenes/S_Settings.unity",
                            "Assets/scenes/S_SceneSelector.unity"};

        string pathToDeploy = "builds/WebGLversion/";       

        BuildPipeline.BuildPlayer(scenes, pathToDeploy, BuildTarget.WebGL, BuildOptions.None);      
    }
}

Then you are ready to compile from command line using the following bat file:

    set mypath=%cd%
    @echo %mypath%
    "C:\Program Files\Unity\Editor\Unity.exe" -quit -batchmode -logFile
 stdout.log -projectPath %mypath% -executeMethod WebGLBuilder.build

i.e. WebGLBuilder becomes a parameter available from command line.

like image 53
Dimitrios Ververidis Avatar answered Sep 20 '22 05:09

Dimitrios Ververidis