---
title: コマンドインターフェースから Unity を実行する
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/unity-editor/command-line-arguments/run-unity
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/unity-editor/command-line-arguments/run-unity.md
last_updated: 2026-10-03
generated_at: 2026-11-16T19:35:00.579Z
locale: ja-jp
---

# コマンドインターフェースから Unity を実行する

> コマンドラインからUnityを起動し、スクリプトを実行する方法を理解します。

オペレーティングシステムのコマンドラインインターフェースフェースから Unity エディターを起動し、引数を渡すことでエディターの起動方法を変更できます。起動時に、コマンドラインを使用してプロジェクトの C# スクリプトから特定のメソッドを実行することもできます。

Unity エディターを起動するとき、コマンド引数値のデリミタは 1 つのスペースです。例えば、ウィンドウモードを borderless に設定するには、`-window-mode borderless` を使用します。

コマンドライン引数の完全なリストについては、[Unity エディター コマンドライン引数リファレンス](/engine/6000.0/manual/unity-editor/command-line-arguments/editor.md)および [Unity Player コマンドライン引数リファレンス](/engine/6000.0/manual/unity-editor/command-line-arguments/player.md)を参照してください。

## コマンドインターフェースフェースからの Unity の起動##launching-unity-from-a-command-line-interface

コマンドラインインターフェースから Unity プロジェクトを起動するには、Unity アプリケーションのディレクトリパスを入力し、その後に `-projectPath` とターゲットプロジェクトのディレクトリパスを入力します。

> **Important:**
>
> プロジェクトのパス名にスペースが含まれている場合は、引用符で囲みます。例えば `"Unity Projects/My Game"` などです。

このように起動すると、エディターは起動時にコマンドと情報を受け取ります。これは、テストスイート、自動ビルド、その他の本番タスクに役立ちます。

エラーが発生した場合は、[Unity ログ ファイル](/engine/6000.0/manual/scripting/debugging-and-diagnostics/log-files.md)を参照して問題の診断に役立つ追加情報を確認してください。

### 前提条件##prerequisites

Unity Hubを使用して、デフォルトの場所に[Unityエディターをインストール](/engine/6000.0/manual/get-started/install-and-upgrade/getting-started-installing-unity.md)します。エディターが別の場所にインストールされている場合は、パスを調整してこれを反映します。エディタの場所のパスを見つける方法の詳細については、[エディタバージョンのインストール](https://docs.unity.com/hub/add-editor.html.md)とアンインストール を参照してください。

### Linux での Unity の起動##launch-unity-on-linux

Unity を起動するには、端末に以下の入力します。

`/home/<user>/Unity/Hub/Editor/<version>/Editor/Unity -projectPath <project path>`

### macOSでUnityを起動##launch-unity-on-macos

Unity を起動するには、端末に以下の入力します。

`/Applications/Unity/Hub/Editor/<version>/Unity.app/Contents/MacOS/Unity -projectPath <project path>`

### Windows での Unity の起動##launch-unity-on-windows

Unity を起動するには、コマンドプロンプトに以下の入力します。

`"C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe" -projectPath "<project path>"`

Windows での構文エラーを防ぐために、ディレクトリリパスが 1 つのバックスラッシュで終了ないようにしてください。次のように、ダブルバックスラッシュ（`\\`）またはバックスラッシュなしのいずれかを使用します。

* `"C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe" -projectPath "C:\MyUnityProjects\MyProject"`
* `"C:\Program Files\Unity\Hub\Editor\<version>\Editor\Unity.exe" -createProject "C:\MyUnityProjects\MyProject\\"`

## 起動時にメソッドを実行するスクリプトの例##example-script-for-executing-methods-at-launch

コマンドラインを使用して、エディター起動時にプロジェクトの C# スクリプトから特定のメソッドを実行できます。以下の例は、Cスクリプトと、起動時にそのスクリプトからメソッドを実行するために使用されるコマンド引数を示しています。

プロジェクトの Cスクリプトの例:

```lang-cs
using UnityEditor;
class MyEditorScript
{
     静的 void PerformBuild ()
     {
        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
        buildPlayerOptions.scenes = new[] { "Assets/Scene1.unity", "Assets/Scene2.unity" };
        BuildPipeline.BuildPlayer(buildPlayerOptions);
     }
}
```

以下のコマンドは、バッチモードでエディターを実行し、前のスクリプトから `MyEditorScript.PerformBuild` メソッドを呼び出し、完了時に終了します。エディターパスで、 `<version>` を起動する Unity のバージョンに置き換えます。Unity エディターパスがデフォルトでない場合、パスを完全に置き換えます。

* **Windows:**

  ```lang-shell
  "C:\Program Files\Unity\Hub\Editor\<version>Editor\Unity.exe" -終了 -batchmode -projectPath "C:\Users\UserName\Documents\MyProject" -executeMethod"
  MyEditorScript.PerformBuild
  ```

* **macOS:**

  ```lang-shell
  /Applications/Unity/Hub/Editor/<version>/Unity.アプリ/Contents/MacOS/Unity -終了 -batchmode -projectPath ~/UnityProjects/MyProject -executeMethod
  MyEditorScript.PerformBuild
  ```

## 追加リソース##additional-resources

* [Unity エディター コマンドライン引数リファレンス](/engine/6000.0/manual/unity-editor/command-line-arguments/editor.md)
* [Unity Player コマンドライン引数リファレンス](/engine/6000.0/manual/unity-editor/command-line-arguments/player.md)
