Using a DLL in a unity project

Hi,

I’m trying to compile a DLL and then import it in my Unity project. I followed the steps mentioned there but it doesn’t work: Unity - Manual: Managed plug-ins

In visual Studio 2010, I created a new solution with a Class Library project. I created a simple class with a public method that returns a string. I changed the project framework to be 3.5 and the target platform to be x86 (without that I had an error) and then compiled the DLL in release and debug mode. (Tried both)

I dragged the newly compiled DLL in the project view in unity beside another C# script. When I open that script in Visual Studio, I see in the project references(Assembly-CSharp-vs) that the DLL is references, but I can’t access any namespace nor class in it.

Back in the unity editor, when I click on the DLL, I can’t expand it and when I click the “open” button in the inspector, I get a warning saying “Unable to open Assets/TestAPI.dll: Check external application preferences”

What should I do to make it work?

By the way, I have Unity v4.2

Thank you for your help.

Ok a few things:

  • You can only “expand” DLLs in Unity that actually contains a class that is derived from MonoBehaviour. “Normal” classes have no meaning to the UnityEditor so it makes no sense to show them as assets.
  • Make sure your class in your DLL is public
  • Make sure that all references your DLL uses / needs are available.