Skip the game client and contract client, and write about the interaction between Unity and the contract.
- In the plugins folder of the Unity project, first create a file with the .jslib extension, and the file name can be customized.
mergeInto(LibraryManager.library, {
StartTime: function(){ // StartTime is the method name called by Unity
BeginTime(); // BeginTime is the method called to the front-end BeginTime() method
},
});
- In Unity, create a script, add the namespace using System.Runtime.InteropServices; and add the following C# code:
[DllImport("__Internal")]
private static extern void StartTime();
- Call the StartTime() method in Unity, which calls the StartTime() method in jslib.
function StartTime() {
}
- Package Unity with WebGL, and choose the compression method as uncompressed.
You can also use the third-party plugin react-unity-webgl in this project to load WebGL resources obtained from the Unity project in a React project.
GitHub: https://github.com/skka3134/plantsVsZombines/tree/main