I have this code:
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
public class UnityEditorClass {
[MenuItem("Tools/Build Project")]
public static void BuildGame()
{
//get the path
var path = EditorUtility.SaveFolderPanel("Save Project", "C:/Projects/MyClasses/", "Test");
//get level name
string[] levels = { "C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/Scene/MyTestScene.unity" };
// Build player
BuildPipeline.BuildPlayer(levels, path + "/Test.exe", BuildTarget.StandaloneWindows, BuildOptions.None);
// Copy a file from the project folder to the build folder, alongside the built game.
FileUtil.ReplaceFile("C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/vector2.dll", path + "/" + "vector2.dll");
FileUtil.ReplaceFile("C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/matrixHelper.dll", path + "/" + "matrixHelper.dll");
// Run the game (Process class from System.Diagnostics).
Process proc = new Process();
proc.StartInfo.FileName = path + "Test.exe";
proc.Start();
}
}
It works fine except, that it doesn’t recognize the file specified when it auto-runs. It gives me this error:
Win32Exception: The system cannot find the file specified.
If anyone has come across this problem and knows how to fix it please share and thanks in advance!