Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 无法从脚本生成Unity WebGL项目_Unity3d_Unity Webgl - Fatal编程技术网

Unity3d 无法从脚本生成Unity WebGL项目

Unity3d 无法从脚本生成Unity WebGL项目,unity3d,unity-webgl,Unity3d,Unity Webgl,我在WebGL目标上构建Unity项目时遇到问题。这只在我试图从脚本构建时出现。当我从Unity项目构建它时,它构建得很好。 我认为这也很重要,我正在从powershell脚本运行此方法 PS脚本: $unityPath = "C:\Program Files\Unity\Editor\Unity.exe" $unityParameters = "-batchmode -projectPath `"$($repo)\`" -username US

我在WebGL目标上构建Unity项目时遇到问题。这只在我试图从脚本构建时出现。当我从Unity项目构建它时,它构建得很好。 我认为这也很重要,我正在从powershell脚本运行此方法

PS脚本:

$unityPath = "C:\Program Files\Unity\Editor\Unity.exe"
$unityParameters = "-batchmode -projectPath `"$($repo)\`" -username USERNAME -password PASS -executeMethod `"BuildScript.PerformBuild`""
$buildProcess = Start-Process -FilePath $unityPath -ArgumentList $unityParameters -Wait -PassThru
我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Build.Reporting;

public class BuildScript
{
     public static void PerformBuild()
     {
         var projectName = "scene_1";
         Debug.Log("### BUILDING ###");
         EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.WebGL, BuildTarget.WebGL);
         var report = BuildPipeline.BuildPlayer(
             new[] {$"Assets/Scenes/{projectName}.unity"}, 
             $"Build/Win/{projectName}.exe", 
             BuildTarget.WebGL,
             BuildOptions.None);
         
         Debug.Log("###   DONE   ###");
 
         Debug.Log(report);
         EditorApplication.Exit(1);
     }
}
我在报告中获取的错误:

切换到WebGL:WebGL支持已禁用

DisplayProgressNotification:生成失败错误生成播放机

生成播放机时出错,因为生成目标不受支持


请检查是否在以下位置安装了WebGL支持:
C:\Program Files\Unity\2020.1.5f1\Editor\Data\PlaybackEngines\WebGLSupport

此错误
切换到WebGL:WebGLSupport被禁用
表示您的Unity安装中可能缺少WebGLSupport

请仔细检查脚本和编辑器中使用的Unity安装是否相同。您可以通过
Show in Explorer
选项检查UnityHub中的路径

您可以尝试在命令行上传递
-buildTarget WebGL
。这就是我们要做的。欢迎来到堆栈溢出。发帖是有规则的,与其他人相比,你做得相当好。然而,标记powershell似乎非常不合适。请相应地标记您的帖子,并通读我在命令行中添加的@RetiredInja主题
-buildTarget WebGL
,但没有任何更改。我还试着从unity运行我的cs脚本,它运行得很好,所以它一定与我的脚本有关@DougMaurer我已经从问题中删除了powershell标签。很抱歉,文档中有一条注释说它在批处理模式下不可用,您应该只使用命令行开关。shrug@RetiredNinja对我来说,
SwitchActiveBuildTarget
在没有
-buildTarget WebGL
的情况下工作得非常好,一切都是从他的代码开始的。也许Unity找不到作为Unity PackageGood call的WebGL!我考虑过这一点,但假设它与在编辑器和脚本中构建时使用的安装相同。