Answer the question
In order to leave comments, you need to log in
Unity 3d and OK JS SDK, API_callback is not defined, what am I doing wrong?
Hello!
We are translating the game into WebGL and launching it in Odnoklassniki. We build the game under WebGL, the index.html code is as follows:
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>GameTitle</title>
<script type="text/javascript" src="//api.ok.ru/js/fapi5.js" defer="defer"></script>
<script src="Build/UnityLoader.js"></script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/game.json");
</script>
</head>
<body>
<div id="gameContainer" style="width: 690px; height: 920px; margin: auto"></div>
</body>
</html>
Application.ExternalEval(
"function API_callback(method, result, data) { }" +
"FAPI.UI.showInvite(\"" + inviteText + "\");"
);
Answer the question
In order to leave comments, you need to log in
Problem solved. It was enough to replace
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/game.json");
</script>
<script>
var gameInstance = UnityLoader.instantiate("gameContainer", "Build/game.json");
function API_callback(method, result, data)
{
var str = "{ \"method\": \"" + method + "\", \"result\": \"" + result + "\", \"data\": \"" + data + "\",}";
console.log(str);
gameInstance.SendMessage(*gameObjectName*, *methodName*, str);
}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question