0

I have written a dll in C# to perform several tasks for my game. I can successfully use that dll when I use it from a C# script in Unity. But when I use the dll from Javascript, it gives this error:

Namespace 'MyLibrary' not found, maybe you forgot to add an assembly reference?

I have placed MyLibrary.dll under Assets folder. This is how I access it from C#:

using MyLibrary;

This is how I access it from Javascript:

import MyLibrary;

So, I can use it from C#, but how can I also use it from Javascript?

3
  • You need to add a reference to the dll Commented May 28, 2016 at 11:20
  • Kindly tell me how? Because in C#, I can use it without adding a reference. Commented May 28, 2016 at 11:21
  • 1
    You're thinking of "Unityscript". It is no longer available in Unity. You must change to c#. Commented May 28, 2016 at 11:57

1 Answer 1

2

NATIVE PLUGIN:

C#:

[DllImport ("PluginName")]
private static extern float functionName ();

JavaScript:

@DllImport (DLLName)
static private function functionName () : float {};

MANAGED PLUGIN:

C#:

using MyLibrary;

JavaScript:

Go to your project directory, look for YourProjectName.CSharp.csproj

Find it, open it and add <Reference Include="MyLibrary"> into it then save it. Restart Unity and Visual Studio.

Put the DLL into the Assets folder.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.