0
0
Unityframework~7 mins

WebGL build in Unity

Choose your learning style9 modes available
Introduction

WebGL build lets you turn your Unity game into a web page that anyone can play in their browser without installing anything.

You want to share your game easily with friends or players online.
You want your game to run on many devices without downloads.
You want to embed your game on a website or blog.
You want quick testing of your game in a browser environment.
You want to reach players who use different operating systems.
Syntax
Unity
1. Open Unity Editor.
2. Go to File > Build Settings.
3. Select WebGL as the platform.
4. Click Switch Platform.
5. Click Build or Build and Run.
6. Choose a folder to save the WebGL build files.

You must have the WebGL Build Support module installed in Unity Hub.

Switching platform may take some time as Unity prepares your project.

Examples
This builds your game and opens it automatically in your default web browser.
Unity
File > Build Settings > Select WebGL > Switch Platform > Build and Run
This creates the WebGL files in a folder so you can upload them to a web server later.
Unity
File > Build Settings > Select WebGL > Switch Platform > Build > Save to folder
Sample Program

This script prints a message to the browser console when the WebGL game starts.

Unity
// This is a Unity C# script example to show a simple message in WebGL build
using UnityEngine;

public class HelloWebGL : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Hello from WebGL build!");
    }
}
OutputSuccess
Important Notes

WebGL builds run inside the browser sandbox, so some features like file access or threading are limited.

Performance may vary depending on the browser and device.

Use browser developer tools (F12) to see console messages and debug your WebGL game.

Summary

WebGL build lets you run Unity games in web browsers without installs.

Use Unity's Build Settings to switch to WebGL and create the build files.

Test your game in browsers and share it easily online.