This project integrates Unity WebGL with a Next.js front end, providing a seamless way to run Unity games or simulations directly within a web application.
Check out the deployed version on Vercel: Unity WebGL
Ensure you have the following installed:
Clone the repository and install dependencies:
git clone https://github.com/your-username/unity-webgl-nextjs.git
cd unity-webgl-nextjs
npm install
# or
yarn install
Start the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 in your browser to see the application.
/unity
: Contains the Unity WebGL build files./components
: React components used throughout the app./pages
: Next.js pages./public
: Static assets, including the Unity WebGL loader and data files.
- Unity Integration: Run Unity games/simulations directly in the browser using WebGL.
- Responsive Design: The Unity canvas adapts to different screen sizes while maintaining the correct aspect ratio.
- Loading Screen: A custom loading screen with a spinning Unity logo while the WebGL build loads.
- Deployed on Vercel: Continuous deployment with Vercel, optimized for performance.
This project is deployed on the Vercel Platform. To deploy your own version, follow these steps:
- Connect your GitHub repository to Vercel.
- Vercel will automatically build and deploy your project on every push to the
main
branch.
To update the Unity WebGL build:
- Build in Unity: Make sure to export your Unity project as a WebGL build.
- Replace Files: Copy the new build files into the
/public/unity/Build
directory. - Replace Streaming Assets: Copy the new asset files into the
/public/unity/StreamingAssets
directory. - Commit & Deploy: Push the changes to GitHub. Vercel will automatically redeploy the updated build.
To integrate your own Unity WebGL build, replace the files in the /public/unity/Build
directory with your own Unity WebGL build files. Any included assets must be placed inside the /public/unity/StreamingAssets
directory. The Next.js app is pre-configured to load these files.
- Next.js: React framework for building web applications.
- Unity: Platform for creating and operating interactive, real-time 3D content.
- React Unity WebGl: Displaying Unity WebGL components.
- Vercel: Hosting platform for modern web projects.
This project is licensed under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a Pull Request.