#Developing C# .dll for use with Unity in Visual Studio
-
Create new project, for type ‘Class Library’
-
Add UnityEngine.dllference to your ClassLibrary.
- Right-click on ClassLibrary, and select Add Reference
-
Go to Browse, and navigate in Unity install directory to find UnityEngine
C:\Program Files (x86)\Unity\Editor\Data\Managed\UnityEngine.dll
-
In Class1.cs, delete the
namespace
block in the generated class templatenamespace ScenarioEngine { class MyUnityClass { } }
-
Add
using UnityEngine;
to class imports -
Add class declaration, using
MonoBehavior
typepublic class MyUnityClass : MonoBehaviour { }
-
Change the Target Framework to .NET Framework 3.5
Right-click on ClassLibrary, and select
.NET Framework 3.5
under Target framework.NET Framework 3.5 does not install by default, select Install other frameworks in the drop-down to be linked to download page on MSDN.
You will need to restart Visual Studio after installing
-
Specify Release build profile in Visual Studio for the dll
-
Build the Solution
-
Open a Unity Project, and add dll. The dll must be added as an Asset into the Plugins folder.
- The Plugins folder is a default member of the Project file structure.
- Right-click on Plugins folder, and select Import New Asset.
-
Locate the dll location in the project
\bin
folderC:\Users\Stan\Documents\Visual Studio 2013\Projects\ScenarioEngine\ScenarioEngine\bin\Release
-
Open a new or existing C# script in MonoDevelop, and develop normally
Initialize objects of type
MyUnityClass
, call functions by dot notation.Auto-complete should include
MyUnityClass
Additional YouTube reference & credit Robert Banister