快速开始
快速开始
1. 导入 SDK 包
在 Unity 编辑器中导入提供的 tudada-unity-client-v0.1.5-hotfix0420.unitypackage 文件。(→ 详细安装指南)
2. 在 C# 代码中使用 API
using Tudada;
public class MyGame : MonoBehaviour
{
void Start()
{
if (!TudadaSDK.Instance.IsAvailable())
{
Debug.LogError("无法使用TudadaSDK");
return;
}
// 登录
TudadaSDK.Instance.Login(
onSuccess: (result) => {
Debug.Log("登录码: " + result.code);
Debug.Log("用户ID: " + result.userId);
},
onFail: (err) => Debug.LogError("登录失败: " + err)
);
}
}
3. WebGL 构建后应用 SDK
Unity WebGL 构建完成后,在生成的 index.html 中添加 TudadaSDK 脚本。(→ 详细应用指南)