Unity has changes how to create server build in 2021
replace:
if (serverBuild)
buildOptions |= BuildOptions.EnableHeadlessMode;
with:
var options = new BuildPlayerOptions();
if (serverBuild)
options.subtarget = (int)(serverBuild ? StandaloneBuildSubtarget.Server : StandaloneBuildSubtarget.Player),
UNITY_SERVER
might now be defined in editor
replace:
#if UNITY_SERVER
with:
#if !UNITY_EDITOR && UNITY_SERVER
replace:
#if !UNITY_SERVER
with:
#if UNITY_EDITOR || !UNITY_SERVER