I created a C++ plugin for Unity and I tried to use it in my game. After having compiled everything on both ends and then copying and pasting the .dll file into my Unity project's "Plugins" folder, I then ran the game and when the function was called the following error was thrown:
Assets/Scripts/C#/Player.cs:73)
Assets/Scripts/C#/Player.cs:73)> DllNotFoundException:
PhysicsEngine.dll AssaultRifle.FireShot () (at Assets/Scripts/C#/AssaultRifle.cs:217) AssaultRifle+c__Iterator1.MoveNext () (at Assets/Scripts/C#/AssaultRifle.cs:151) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) Player:GetInput() (at Assets/Scripts/C#/Player.cs:73)Assets/Scripts/C#/Player.cs:73)
Assets/Scripts/C#/Player.cs:73)
The code that I wrote for the C++ is shown in the following:
extern "C"
{
...
const EXPORT_API char* HelloWorld()
{
return "Hello World! ^_^
";
}
For the C# file, I have the following:
public class AssaultRifle:Weapon
{
[DllImport("PhysicsEngine")]
private static extern string HelloWorld();
...
private void FireShot()
{
print(HelloWorld());
If there's anyone who's had this kind of experience with trying to import C++ plugins into Unity and know how to solve this problem, then please let me know. I really have no idea how to resolve this problem right now. Thanks in advanced.