今後はUnityを使ってアプリを作って行きたかったのでインストールしました。
デバックはVisual Studio Codeでやりたかったので連携する方法を調べて実施したのでまとめます。

Visual Studio Codeと Unityの連携は大体下記から。
https://qiita.com/eighty8/items/10af094e974a7a3e749e


まずは.Net Coreをインストール。


次はVisual Studio Codeで以下のプラグインをインストールする。
「C#」、「Debugger for Unity」、「Mono Debug」

16

53

30



細かいところは省略。
Preferenceの「External Tools」をいじって、「VSCode」の項目を追加したりした。 
githubでダウンロードした「VSCode.csharp」ファイルを「Assets」フォルダ下に格納することも必要。
Assets/Plugins/Editer/ というパス構成の方がわかりやすいか。 
大体参考通り。



Unityのプロジェクトフォルダ内のC#を開いて、Visual Studio Codeが自動起動するか確認。
起動したけど、エラーメッセージが出てきた。

43

CLIをインストールしたにも関わらずインストールしろとメッセージが出てきた。
画像の通りである。

「.net cli tools cannot be located」

対処法は下記から。
https://qiita.com/TsuyoshiUshio@github/items/7cd5634a66efe32b7aa7

cd /usr/local/share/dotnet && ls

 sudo rm -rf dotnet


 cd /etc/paths.d && ls

 sudo rm dotnet



これで解決した。
色々あって複数回インストールファイルを実行したのが原因だろうか。


あとはこんなメッセージが出てきた。
「spawn mono ENOENT。デバッグ アダプターを停止しています。」

monoを別途インストールする必要があったみたい。
https://github.com/dotBunny/VSCode/issues/74

 brew install mono


==> Downloading https://homebrew.bintray.com/bottles/mono-5.0.1.1.sierra.bottle.tar.gz

######################################################################## 100.0%

==> Pouring mono-5.0.1.1.sierra.bottle.tar.gz

==> Caveats

To use the assemblies from other formulae you need to set:

  export MONO_GAC_PREFIX="/usr/local"

Note that the 'mono' formula now includes F#. If you have

the 'fsharp' formula installed, remove it with 'brew uninstall fsharp'.

==> Summary

🍺   /usr/local/Cellar/mono/5.0.1.1: 2,579 files, 315.4MB




最終的にUnityのプロジェクトフォルダ内のC#を開いて、自動的にVisual Studio Codeが起動して、下記の画像の通りになったらOK。
デバックはUnity側、Visual Studio Code側両方でデバックをスタートする必要がある。

50


*再度Unity開いたら下記のメッセージが出ていた。

Editor: Metal support disabled, skipping device initialization

参考
http://robamemo.hatenablog.com/entry/2017/06/16/140325


*プレイモードのON/OFFのやり方
なんか勝手に画面がグレー色になったので直す方法を探した。
command + pらしい。 
https://www.experts-exchange.com/questions/29005155/How-to-get-out-of-play-mode-in-Unity.html