unity3d webgl js代码交互
小艺001
2021.10.14 14:43发布于技术 - 前端与UI
5190
详细文档参阅 https://docs.unity3d.com/Manual/webgl-interactingwith

html->unity3d

html

注意

  • colorCube为游戏对象名称
  • RedMe为脚本中的函数名
unityInstance.SendMessage('colorCube', 'RedMe');

unity3d配置

image.png

脚本代码

using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChangeMat : MonoBehaviour { public Material redMat; public Material blueMat; public void RedMe() { // 你的集成代码 } }

unity3d->html

脚本代码1

注意事件名称HelloString根据需要进行修改

mergeInto(LibraryManager.library, {

  HelloString: function (str) {
    ReactUnityWebGL.HelloString(Pointer_stringify(str));
  },

});

脚本代码2

事件名 事件参数
HelloString This is a string.
using UnityEngine; using System.Runtime.InteropServices; public class NewBehaviourScript : MonoBehaviour { [DllImport("__Internal")] private static extern void HelloString(string str); void Start() { HelloString("This is a string."); } }
颂文Gavin、作者在、小晴天
点赞
收藏
手机查看
举报
0个评论
倒序看帖
仅看楼主

暂无数据