Using c#6.0 in Unity

Source: Internet
Author: User

Sun Guangdong 2015.9.28

New features in C # 6.0 include:

Can I use C # 6.0 in Unity?

Of course you can!

Unity uses the structure of CLR 2.0 for a long time, but almost all the latest C # featuresthe latest version of the CLR is not required。 The Microsoft and mono compilers can compile C # 6.0 code for CLR 2.0.
The late binding (dynamic) feature that comes with C # 4.0 is still not available in unity because it relies on CLR 4.0 and we haven't.

All right, what should I do?
1. Copy the Smcs\smcs\bin\release\smcs.exe from this library to the \unity\editor\data\mono\lib\mono\2.0 folder. Just copy, nothing to replace.

2. Create a new Unity project or open an existing one. Please make sure that theProject Settings/Player/API Compatibility Level(compatibility level) is set to. Net 2.0.

3. Copy the Mcs.exe or Roslyn folder to your project root.

That's it.

How does it work?

Smcs.exe Receive and redirect compilation requests from Unity to an available C # compiler using the following rules:
1. If the current project contains the Roslyn folder, then the Roslyn C # 6.0 compiler will be used;
2. Otherwise if the current project contains Mcs.exe, then this mono C # 6.0 compiler will be used;
3. Otherwise if there is a AsyncBridge.Net35.dll (multithreaded correlation) somewhere inside the project, then Unity's 5.0 C # compiler will be used (\unity\editor\data\monobleedingedge\lib\ Mono\4.5\mcs.exe);
4. Otherwise the storage compiler will use (\unity\editor\data\mono\lib\mono\2.0\gmcs.exe).
It means that Unity would use the alternative compiler only in those projects, where you have explicitely expressed your WI SH to does so. Otherwise, it'll use the stock compiler as usual, and the only bad thing that can happen are if smcs.exe crashes for what Ever reason instead of doing its job. Then you can just delete it and continue as if the nothing ever happened.
It means that unity will use another compiler only in these projects, where you have a clear indication that you want to do so. Otherwise it will use the storage compiler as usual,The only bad thing is that if smcs.exe crashes for whatever reason instead of doing its job. Then you can delete it and continue as if nothing had happened.






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Using c#6.0 in Unity

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.