First of all, compiling your code into a DLL
only makes it more difficult for people to read it. It doesn't encrypt it per se.
Still, if you want to compile your code into a .dll, you'd need to make a new project in VS/MonoDevelop and set the outbut to Class Library
. Then, after building your code you should get a nice 'n round DLL
file in the bin
folder. As far as I can tell, you can then embed this file into your Unity project by just drag and dropping it onto the Project window.
More info here: Managed Plugins
Also, remember that with this approach comes an important limitation (well, it isn't a limitation exactly, but it can get confusing at first). You're creating another aassembly, so you can't reference your regular .cs files directly from the classes in the .DLL file. That means that you should keep it standalone.
Also, as a side note: It's not always a good idea to compile your asset's code into a DLL file -- especially if the classes inside are using UnityEngine.*
or UnityEditor.*
namespaces. The Unity editor is constantly changing, and with each update the Scripting API changes.
If you decide to package the code this way, you should take responsibility for it working on future versions of Unity, since most people won't know how to fix eventual errors.