Writing latest C# in Unity

Unity is one of the most popular game engine. However, one of the most annoying thing is the compiler does not support the latest C#. Although we cannot use the all the latest feature in Unity, some of them does not need latest CLR. You can also write in latest syntax if you want.

Instead of writing this.

public int Size
    get { return _list.Count; }

You can now writing this.

public int Size => _list.Count;

The workaround is simple. First, you have to install Visual Studio Tools for Unity. Also, there is a option when you install or upgrading Unity.

Instead of programming in Unity, you now program in Visual Studio (Not launch from Unity either). You create a class library project and set its target framework to “Unity 3.5 .net full Base Class Libraries”.

Then, you just programming like when you are in Unity. After that, build the library in .dll and put them in your Unity project. If you want to use any Unity class, you have to add a reference to your project. They are located at

<Installation Path>\Editor\Data\Managed\UnityEngine.dll

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s