Unity3D calls DLL dynamic link library

1. Open vs2017 to create a new project

2. Choose Windows Desktop>Dynamic Link Library (DLL)

3. Define a C++ addition function

4. Generate DLL dynamic link library

5. Create a plugins folder under Assets in unity, and put the DLL in it (must be put under plugins, otherwise unity will not recognize it)

6. Create a new Test.cs script under unity

using UnityEngine;
using System.Runtime.InteropServices;

public class Test : MonoBehaviour
{
    [DllImport("Dll1")]
    public static extern int add(int a, int b);
    void Start()
    {
        print(add(10, 20));
    }
}

7. Drag and drop the Test.cs script onto the Main Camera

8. Running results

Guess you like

Origin blog.csdn.net/zhunju0089/article/details/103458855