📖 Scenario: You want to share a small 3D scene you made in Unity on a website. To do this, you need to create a WebGL build that can run in web browsers.
🎯 Goal: Build a Unity WebGL project step-by-step and prepare it for deployment on a website.
📋 What You'll Learn
Create a new Unity project with a simple 3D scene
Set the build target to WebGL
Configure WebGL build settings
Build the project to generate WebGL files
💡 Why This Matters
🌍 Real World
WebGL builds let you share interactive 3D content on websites without requiring users to install software.
💼 Career
Many game studios and interactive media companies use Unity WebGL builds to deliver browser-based experiences.
Progress0 / 4 steps
1
Create a new Unity project with a simple 3D scene
Open Unity Hub and create a new 3D project named WebGLDemo. In the new project, add a Cube GameObject to the scene and save the scene as MainScene.
Unity
Hint
Use Unity Hub to create the project. Use the Hierarchy window to add a Cube. Use File > Save As to save the scene.
2
Set the build target to WebGL
In Unity Editor, open File > Build Settings. Select WebGL as the platform and click Switch Platform to set WebGL as the build target.
Unity
Hint
Build Settings window lets you choose the platform. Switching to WebGL prepares Unity to build for browsers.
3
Configure WebGL build settings
In the Build Settings window, add the MainScene to the Scenes In Build list by clicking Add Open Scenes. Then click Player Settings, go to the Resolution and Presentation section, and set Default Canvas Width to 960 and Default Canvas Height to 540.
Unity
Hint
Adding the scene ensures it is included in the build. Adjusting canvas size controls the WebGL display size.
4
Build the project to generate WebGL files
In the Build Settings window, click Build. Choose a folder named WebGLBuild inside your project directory to save the build files. Wait for Unity to finish building the WebGL project.
Unity
Hint
The Build button starts the WebGL build process. Choose a clear folder name to keep files organized.
Practice
(1/5)
1. What is the main purpose of creating a WebGL build in Unity?
easy
A. To export games as console packages
B. To create mobile apps for Android and iOS
C. To run Unity games directly in web browsers without installation
D. To build desktop applications for Windows and Mac
Solution
Step 1: Understand WebGL build purpose
WebGL build allows Unity games to run inside web browsers without needing users to install anything.
Step 2: Compare with other build targets
Other build targets like Android or desktop require installation, unlike WebGL.
Final Answer:
To run Unity games directly in web browsers without installation -> Option C
Quick Check:
WebGL build = run in browser [OK]
Hint: WebGL = play games in browser, no install needed [OK]
Common Mistakes:
Confusing WebGL with mobile or desktop builds
Thinking WebGL requires app installation
Assuming WebGL builds are for consoles
2. Which Unity menu option do you use to switch your project to WebGL build target?
easy
A. Window > Package Manager
B. Edit > Preferences
C. File > New Project
D. File > Build Settings
Solution
Step 1: Locate build target settings
Unity uses the Build Settings window to select and switch build targets like WebGL.
Step 2: Confirm correct menu path
The Build Settings window is accessed via File > Build Settings, not other menus.
Final Answer:
File > Build Settings -> Option D
Quick Check:
Switch build target = Build Settings [OK]
Hint: Build Settings is where you pick WebGL target [OK]
Common Mistakes:
Choosing Edit > Preferences which is for editor settings
Selecting Window > Package Manager which manages packages
Confusing File > New Project with build settings
3. After building a Unity WebGL project, which file do you open in a browser to start the game?
medium
A. game.exe
B. index.html
C. main.unity
D. build.json
Solution
Step 1: Identify WebGL build output files
Unity WebGL build creates an index.html file to launch the game in browsers.
Step 2: Understand file roles
Other files like .exe or .unity are not used for WebGL browser launch.
Final Answer:
index.html -> Option B
Quick Check:
Open index.html to run WebGL game [OK]
Hint: Open index.html to play WebGL game in browser [OK]
Common Mistakes:
Trying to open .exe files which are for desktop
Confusing build.json as launch file
Attempting to open .unity files directly
4. You built your Unity project for WebGL but the game does not load in the browser. What is a common cause?
medium
A. Not running a local or remote web server to serve the files