I've been developing games in Unity for the past 7 years. Compilation, especially for multiple platforms, has always been an annoyance.

I recently found out by creating a CI/CD pipeline with git that unity has a decently documented CLI one can use for compilation and that it was a perfect fit for my game, Nonno Lorenzo , since that project is not current on GitHub.

I did some research and created a batch script that compiles my game for Mac, Linux and Windows without requiring any manual input. I just double click the batch file and wait for the builds to complete.

@echo off
title Unity Project Builder
set "ProjectPath=D:\NonnoLorenzo\Nonno Lorenzo"
set "LogPath=D:\NonnoLorenzo\build-log.txt"
set "BuildPath=G:\Nonno Lorenzo\Builds\Latest"
set "AppName=Nonno Lorenzo"
set "Editor="D:\Unity Editors\2021.1.0f1\Editor\Unity.exe""

@REM start "Unity Build Logs" powershell.exe /c "Get-Content build-log.txt -wait"

rem Build for Windows
echo Building for Windows...
%Editor% -quit -batchmode -projectpath "%ProjectPath%" -buildWindowsPlayer "%BuildPath%\Windows\%AppName%.exe" -logFile "%LogPath%"

rem Build for macOS
echo Building for macOS...
%Editor% -quit -batchmode -projectpath "%ProjectPath%" -buildOSXUniversalPlayer "%BuildPath%\Mac\%AppName%.app" -logFile "%LogPath%"

rem Build for Linux
echo Building for Linux...
%Editor% -quit -batchmode -projectpath "%ProjectPath%" -buildLinux64Player "%BuildPath%\Linux\%AppName%.x86_64" -logFile "%LogPath%"

@echo Zipping Projects ...

rem Zip for Windows
powershell -Command "Compress-Archive -Path '%BuildPath%\Windows\*' -DestinationPath '%BuildPath%\Windows\%AppName%.zip' -Force"

rem Zip for macOS
powershell -Command "Compress-Archive -Path '%BuildPath%\Mac\*' -DestinationPath '%BuildPath%\Mac\%AppName%.zip' -Force"

rem Zip for Linux
powershell -Command "Compress-Archive -Path '%BuildPath%\Linux\*' -DestinationPath '%BuildPath%\Linux\%AppName%.zip' -Force"

Simply change the environment variables to fit your own needs :)

More posts