Reinforcement learning with Unity Part 2 — Setting up Unity for scripting (C#)

Josh Yang
4 min readSep 19, 2021

Hi everyone, welcome back to the second part of my journey to implementing Reinforcement learning using Unity. In the previous article we installed Unity and created our first project! In this article we are going to go through how to set up Unity for scripting in this article so let’s get started!

Background — Scripting?

In Unity, we can make any 3D object as we wish from simple objects like a cube or a cylinder to complex combination of objects like a robotic arm using a variety of types of joints. However, in order for us to control the objects or to define certain mechanical characteristics of the objects we need to do some coding.

Unity’s choice of programming language is C# which is designed by Microsoft. I am not going to go into all the details of C# language itself and for this journey it is not at all crucial if you aren’t familiar with C#. The code I will be writing should be self-explanatory but I will also be explaining them in detail as well.

So let’s get started!

Installing Visual Studio Code (VS Code)

If you already know how to code then I am sure you have your favourite go-to IDE (integrated development environment) of your choice. But the most convenient IDE to use with Unity is VS Code. They are really well integrated with each other with a bunch of extensions that can help make your life a lot easier. So I do recommend that you download and install VS Code but this is not a must. You can still use your favourite IDE.

So to start, go to the download page to install VS Code. Choose the right installer for your operating system. I am using Ubuntu 20.04.2 LTS so I downloaded .deb file.

You can then follow the instructions to install VS Code.

Setting up VS Code

We have now installed VS Code so we will set up VS Code with the extensions for Unity.

Open VS Code and select on the top left hand side tab “File” -> “Preferences” -> “Extensions”. Or you can simply press ctrl + shift + x on your keyboard.

We will install just 2 extensions for now (but feel free to look into different extensions you think will be helpful).

  1. In the search bar type in “unity” and install “Unity Code Snippets” extension.
  2. In the search bar type in “c#” and install “C#” extension.

You are all set on the VS Code side!

Installing VS Code extensions

Setting up on Unity for scripting

Open the project named “OurFirstProject” we have created from the previous article.

Update all packages

We have to go to the “Package Manager” by selecting on the top tab “Window” -> “Package Manager”. You should definitely remember how to get to this Package Manager as this is where all of the Unity packages are managed so it will be very important later on.

Make sure the default Unity packages are all up to date — on mine “Visual Studio Code Editor” package was not up to date so I updated. You can see how I did that below.

Updating packages in Package Manager

Link up VS Code with Unity

We need to now link VS Code with Unity so when we click on a script file in Unity it automatically opens VS Code.

On the top select “Edit” -> “Preferences”. Click on “External Tool” section on the left pane. Select the option to the correct path to where VS code is installed (for mine it is installed in /usr/bin/code). You can find where your VS Code is installed by googling.

Linking up VS Code with Unity

That’s it!

We are now finally ready with setting up VS Code and Unity for scripting! In the next article we will make a simple cube and write some code to move it around!

Thank you for reading this article and hopefully this was helpful!

--

--