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 customize the file name.
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 using WebGL, and choose the compression method as uncompressed.
You can also use the third-party plugin react-unity-webgl in a React project to load the WebGL resources obtained from the Unity project.
GitHub: https://github.com/skka3134/plantsVsZombines/tree/main